Reputation: 347
I am using the facebook android sdk to access the user's facebook albums and intern get the photos.
But when I do a "https://graph.facebook.com/"+wallAlbumID+"/photos?access_token="+facebook.getAccessToken()
it returns blank data. { "data": [] }
I read in stackoverflow question and also in Graph API for Photo that I need to give user_photos
permission while creating the facebook object.
I am not sure how to do so.I read a lot of forums and also checked on SOF but could not find the solution.
This is how I am creating the facebook object
facebook = new Facebook(APP_ID);
Can anyone please help me with this.
Upvotes: 3
Views: 4312
Reputation: 26824
You need to use Facebook SDK 3.0+. Also, enable the OAuth client login flow in the developer settings on the FB site. Then you can use the following code:
First, log the user into FB inside of your app to get a Session object, then request permissions for user_photos if not granted yet:
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// check for permission to see user photos
if (!hasPhotoPermissions())
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(MyActivity.this, "user_photos"));
else {
// photos permission granted, fetch user's albums
fetchAlbumsFromFB(session);
}
}
}
});
Here is what hasPhotoPermissions() method looks like:
private boolean hasPhotoPermissions() {
Session session = Session.getActiveSession();
return session.getPermissions().contains("user_photos");
}
Your app will then present the photos permissions screen to the user for approval.
Upvotes: 2
Reputation: 377
You need to create an ArrayList
of permissions you want to access. For example, when I did it, when declaring variables.
private static final String[] PERMISSIONS = { "user_photos" };
Then, when implementing the user login area:
if (!facebook.isSessionValid()) {
facebook.authorize(this, PERMISSIONS, new LoginDialogListener());
}
Hope this helps!
Upvotes: 2