简体   繁体   English

使用Facebook SDK SDK for Android获得额外权限登录

[英]Login with extra permission with Facebook SDK 3 for Android

I followed the step of "Create a new Android Project with Facebook Login" section at https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ The login process is fine. 我在https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/中执行了“使用Facebook登录创建新的Android项目”部分的步骤,登录过程很好。 Because I would like to use the native Android button for a user to log in, I modify the code slightly by moving the following code into a View.OnClickListener() of a native Android button. 因为我想使用本机Android按钮供用户登录,所以我通过将以下代码移动到本机Android按钮的View.OnClickListener()中,对代码进行了一些修改。 The following is the code in the listener: 以下是侦听器中的代码:

Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
    // callback when session changes state
    @Override
    public void call(Session session,SessionState state, Exception exception) {
        if (session.isOpened()) {                           
            // make request to the /me API
            Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {

                // callback after Graph API
                // response with user object
                @Override
                public void onCompleted(GraphUser user,Response response) {
                    if (user != null) {
                        Toast.makeText(getApplicationContext(), "Hello " + user.getName() +" "+user.getId()+"!", Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
});

The onActivityResult() and AndroidManifest.xml is the same as the tutorial onActivityResult()和AndroidManifest.xml与本教程相同

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

However, I would like to request get "read_friendlists" when a user logs in successfully. 但是,当用户成功登录时,我想请求获取“ read_friendlists”。 I read the tutorial at https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ but it uses Facebook SDK customized button. 我在https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/中阅读了该教程,但是它使用了Facebook SDK自定义按钮。 How can I achieve the same behavior with a native Android button like my code shown above? 如何使用Android本机按钮实现相同的行为,如上面的代码所示?

I just answered a similar question on another post. 我在另一个帖子上回答了类似的问题。 My solution allows you to use a native button and request additional read permissions when the user first logs in. Check it out here Ask for more permissions with 3.0 SDK 我的解决方案允许您在用户首次登录时使用本机按钮并请求其他读取权限。在此处进行检查要求使用3.0 SDK的更多权限

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

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