Tiago Oliveira Tiago Oliveira - 2 months ago 47
Android Question

Facebook Graph API getCover not working anymore

STORY



I have an app on playstore that downloads the cover photo of the user and sets as the backgound of the drawer.

What Happend?

It stopped working i was using the link below it was working like a charm, but it's not working anymore, now i only get the id of the user but no cover

What was working before ?

https://graph.facebook.com/{my id}?fields=cover&access_token={my token}


Troubleshoot



I thought that maybe was something that i did without noticing in my code, so downloaded my app from the playstore and i got the same problem the cover is not being downloded so at this point im almost sure that the problem is something to do with facebook itself

I belive is something to do with permissions because i get a responce but not the
source
of the cover but if it was working with my user i don't know why isn't this working anymore

Failed Attemps to fix the problem



I went to Facebook Developers page and i tried this

new GraphRequest(
AccessToken.getCurrentAccessToken(),
"...?fields=cover",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.d(TAG, response.toString());
}
}
).executeAsync();


Sadly this didn't work, in facebook developers page they show this
"...?fields={fieldname_of_type_CoverPhoto}"
i belive
fieldname coverPhoto
is
cover
like i see here

Result



This will log

{Response: responseCode: 404, graphObject: null, error:
{HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803)
Some of the aliases you requested do not exist: ...}}


I tried to remove the 3 dots and i tried to add
me?fields=cover
got this:

{Response: responseCode: 404, graphObject: null, error:
{HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803)
Some of the aliases you requested do not exist: fields=cover}}


EDIT



I tried this

Bundle params = new Bundle();
params.putString("fields", "id,email,gender,cover,picture.type(large)");
new GraphRequest(AccessToken.getCurrentAccessToken(), "me", params, HttpMethod.GET,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (response != null) {
try {
JSONObject data = response.getJSONObject();
Log.d(TAG, data.toString());
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "ERROR");
}
}
}
}).executeAsync();


this prints all my information but no cover

Answer

I was able to fix this issue

It seems that now we need to use user_photos permission, i belive this was something changed recently because my app was on the playstore for almost a month working perfectly without user_photos

Remeber that you need to request a new permisson, you can do that with this

if(!AccessToken.getCurrentAccessToken().getPermissions().contains("user_photos")) {
     LoginManager.getInstance().logInWithReadPermissions(
     this,
     Arrays.asList("user_photos"));
}