【问题标题】:Facebook SDK 3.0 - Get Facebook User ID and Access TokenFacebook SDK 3.0 - 获取 Facebook 用户 ID 和访问令牌
【发布时间】:2013-02-28 04:53:35
【问题描述】:

我搜索了这两天,没有成功找到从 Facebook SDK 3.0 - Native Login 获取用户 ID 和访问令牌的方法。

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

我使用Session.getAccessToken 获得访问令牌,我获得了一些访问令牌,但这是无效的。实际程序是什么?我做错了吗?

如何使用 Facebook SDK 3.0 在 Native Login 中获取 UserId

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    用户名:

    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 是字符串。

    对于 accessToken:

    String token = session.getAccessToken();
    

    已编辑:(2014 年 13 月 1 日)

    对于用户电子邮件(我没有通过在设备或模拟器上运行来检查此代码):

    这些只是我的意见,或者你可以称之为建议

    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");
    

    有关更多信息,请参阅: link1, link2, link3, link4,

    【讨论】:

    • 这里如何获取用户邮箱??
    • @user2843350 :我在EDITED: (13/1/2014) 部分提出了一些建议,请查看并告诉我。 P.S.:我很久没有使用 Facebook SDK 了
    猜你喜欢
    • 2018-07-04
    • 2012-05-17
    • 2012-08-13
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 2014-06-10
    • 1970-01-01
    相关资源
    最近更新 更多