android - Facebook SDK 3.0 - 获取 Facebook 用户 ID 和访问 token

标签 android facebook

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

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

并且我使用 Session.getAccessToken 获取了访问 token ,我获得了一些访问 token ,但那是无效的。实际程序是什么?我做错了吗?

如何使用 Facebook SDK 3.0 在 native 登录中获取 UserId

最佳答案

用户编号:

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

对于访问 token :

String token = session.getAccessToken();

编辑:(13/1/2014)

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

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

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 ,

关于android - Facebook SDK 3.0 - 获取 Facebook 用户 ID 和访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15127783/

相关文章:

android - Ionic Firebase 是否具有与原生相同的功能?

android - 当我在自定义适配器中使用图像按钮时,setOnItemClickListener 在 ListView 中不起作用

android - OKHttp默认的重试策略机制是什么? (安卓)

iphone - Facebook Feed 对话框不断请求许可

ios - iOS 9 上的 Facebook 应用邀请,最后一个 FB iOS SDK 缩小了

android - Google home 发送卡片到 Google Home 应用

android - 找不到与给定名称 dialogCornerRadius 匹配的资源

facebook 应用程序,通知用户

Facebook API : manage_pages permission is not working

facebook - 使用 Koala 在 Facebook 中获取用户访问 token