简体   繁体   English

Facebook SDK 3.0 - 获取Facebook用户ID和访问令牌

[英]Facebook SDK 3.0 - Get Facebook User ID and Access Token

I searched for past two days and was not successful in finding the method to get the user id and access token from Facebook SDK 3.0 - Native Login . 我搜索过去两天并没有成功找到从Facebook SDK 3.0获取用户ID和访问令牌的方法 - 本地登录。

i am following facebook native login - http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ 我正在关注facebook本地登录 - http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/

and i get the access token using Session.getAccessToken , i get some access token but that is not valid . 我使用Session.getAccessToken获取访问令牌,我获得了一些访问令牌,但这是无效的。 what is the actual procedure ? 什么是实际程序? Am i doing wrongly ? 我做错了吗?

How to get the UserId in Native Login using Facebook SDK 3.0 如何使用Facebook SDK 3.0获取本地登录中的UserId

user id: 用户身份:

final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        // If the session is open, make an API call to get user data
        // and define a new callback to handle the response
        Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                // If the response is successful
                if (session == Session.getActiveSession()) {
                    if (user != null) {
                        user_ID = user.getId();//user id
                        profileName = user.getName();//user's profile name
                        userNameView.setText(user.getName());
                    }   
                }   
            }   
        }); 
        Request.executeBatchAsync(request);
    }  

user_ID & profileName are string. user_IDprofileName是字符串。

for accessToken: for accessToken:

String token = session.getAccessToken();

EDITED: (13/1/2014) 编辑:(13/1/2014)

for user email (i haven't check this code by running on device or emulator): 用户电子邮件(我没有通过在设备或模拟器上运行来检查此代码):

these are only my opinion or you can call it suggestion 这些只是我的意见,或者你可以称之为建议

setReadPermissions(Arrays.asList("email", ...other permission...));
//by analyzing the links bellow, i think you can set the permission in loginbutton as:
loginButton.setReadPermissions(Arrays.asList("email", ...other permission...));
user.asMap().get("email");

for more info see: link1 , link2 , link3 , link4 , 有关更多信息,请参阅: link1link2link3link4

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

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