我搜索了过去两天,并没有成功找到从Facebook SDK 3.0 – 本地登录获取用户标识和访问令牌的方法.
我正在跟随facebook本地登录 – http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/
我使用Session.getAccessToken获取访问令牌,我得到一些访问令牌,但是这是无效的.实际程序是什么?我做错了吗
解决方法
用户名:
- 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();
EDITED:(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");