Facebook SDK 3.0 - 获取Facebook用户名和访问令牌 [英] Facebook SDK 3.0 - Get Facebook User ID and Access Token

查看:88
本文介绍了Facebook SDK 3.0 - 获取Facebook用户名和访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了过去两天,并没有成功找到从Facebook SDK 3.0 - 本地登录获取用户ID和访问令牌的方法。

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本机登录 - http://developers.facebook.com/docs/tutorials/androidsdk/ 3.0 / scrumptious / authenticate /

i am following facebook native login - http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/

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

and i get the access token using Session.getAccessToken , i get some access token but that is not valid . what is the actual procedure ? Am i doing wrongly ?

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

How to get the UserId in Native Login using Facebook SDK 3.0

推荐答案

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

user_ID & profileName are string.

for accessToken:

for accessToken:

String token = session.getAccessToken();

已编辑:(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");

有关详细信息,请参阅:
link1 link2 link3 link4

for more info see: link1, link2, link3, link4,

这篇关于Facebook SDK 3.0 - 获取Facebook用户名和访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆