Reputation: 4106
I'm using the Android version of the facebook graph-API. And to handle login, we do a simple authorize dialog, which will call the onComplete if everything works fine. However the problem is that I need the user ID, so I need to make a sequential facebook.request("me")
to grab that. Is there a way to get the user ID in the authorization logic?? The bundle values only return the acess_token and expire_time
facebook.authorize(this, permissions, new DialogListener() {
@Override
public void onComplete(Bundle values) {
login();
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
Upvotes: 2
Views: 459
Reputation: 4106
Ok, after some googling I found some info about the access_token. One cool part is that it contains a substring that identify the user ID. The access token have this format:
116122545078207|2.1vGZASUSFMHeMVgQ_9P60Q__.3600.1272535200-500880518|QXlU1XfJR1mMagHLPtaMjJzFZp4.
The part that identify the User ID is from the second |
to the first left -
, so the user ID of the access token above is: 500880518
To grab it, just do:
public void onComplete(Bundle values) {
String token = values.getString("access_token");
String[] firstPart = token.split("\\|");
String[] subPart = firstPart[1].split("-");
long id = Long.parseLong(subPart[subPart.length - 1]);
}
Upvotes: 1
Reputation: 16110
simply no... you have to call user/me for that. but you can have it sequentialy after the authorize complete call because in order to get any kind of info from facebook that is not public you need the token and authorize just returns authentication info. what you are asking is like wanting to get the friend list by calling for a wall post.. the calls aren't interconnected.
Upvotes: 0