简体   繁体   English

在Android中如何添加user_photos权限来获取facebook专辑照片?

[英]In Android how to add user_photos permission to get the facebook album photos?

I am using the facebook android sdk to access the user's facebook albums and intern get the photos. 我正在使用facebook android sdk访问用户的脸书专辑和实习生获取照片。 But when I do a "https://graph.facebook.com/"+wallAlbumID+"/photos?access_token="+facebook.getAccessToken() it returns blank data. 但是,当我执行"https://graph.facebook.com/"+wallAlbumID+"/photos?access_token="+facebook.getAccessToken()它会返回空白数据。 { "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. 在stackoverflow问题Graph API for Photouser_photos了我需要在创建facebook对象时给予user_photos权限。 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. 我不知道该怎么做。我阅读了很多论坛,并检查了SOF,但找不到解决方案。

This is how I am creating the facebook object 这就是我创建facebook对象的方式

facebook = new Facebook(APP_ID);

Can anyone please help me with this. 任何人都可以帮我这个。

You need to create an ArrayList of permissions you want to access. 您需要创建要访问的权限的ArrayList 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! 希望这可以帮助!

You need to use Facebook SDK 3.0+. 您需要使用Facebook SDK 3.0+。 Also, enable the OAuth client login flow in the developer settings on the FB site. 此外,在FB站点的开发人员设置中启用OAuth客户端登录流程 Then you can use the following code: 然后您可以使用以下代码:

  1. 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: 首先,将用户登录到应用程序内部的FB以获取Session对象,然后在未授权的情况下请求user_photos的权限:

     // 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); } } } }); 
  2. Here is what hasPhotoPermissions() method looks like: 这是hasPhotoPermissions()方法的样子:

     private boolean hasPhotoPermissions() { Session session = Session.getActiveSession(); return session.getPermissions().contains("user_photos"); } 
  3. Your app will then present the photos permissions screen to the user for approval. 然后,您的应用会将照片权限屏幕显示给用户以供审批。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM