2013-02-28 170 views

回答

38

用户ID来获得在本地登录的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是字符串。

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

更多信息,请参阅: link1link2link3link4

+0

这里如何获得用户的电子邮件? – 2014-01-13 12:36:02

+0

@ user2843350:我在'EDITED:(13/1/2014)'部分提出了一些建议,请检查并告诉我。 P.S. .:我很长时间没有在Facebook SDK上工作 – Shoshi 2014-01-13 14:40:33