9

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 .

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

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 ?

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

4

1 に答える 1

38

ユーザー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_IDprofileNameは文字列です。

accessTokenの場合:

String token = session.getAccessToken();

編集済み:(2014年1月13日)

ユーザーの電子メールの場合(デバイスまたはエミュレーターで実行してこのコードを確認していません):

これらは私の意見にすぎないか、提案と呼ぶことができます

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、を参照してください。

于 2013-02-28T05:30:58.533 に答える