获取的Facebook用户ID和访问令牌

获取的Facebook用户ID和访问令牌

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

问题描述

我搜索了过去的两天,没有成功在寻​​找方法来获取来自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,以获得用户ID 在本地登录

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

推荐答案

用户名:

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.

有关accessToken:

for accessToken:

String token = session.getAccessToken();

编辑:(13/1/2014)

有关用户的电子邮件(我还没有通过在设备或模拟器上运行检查该code):

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用户ID和访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 09:54