I’m trying to retrieve in my android app(in which I have facebook integrated ) the personal information for the logged in user.
For this I have 2 buttons:
Button tweet = (Button) findViewById(R.id.btn_post);
Button information = (Button) findViewById(R.id.btn_information);
The first button when pressed does a login like this:
tweet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postMessage();
}
});
where postMessage() looks like:
public void postMessage() {
if (facebookConnector.getFacebook().isSessionValid()) {
postMessageInThread();
} else {
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
@Override
public void onAuthSucceed() {
postMessageInThread();
}
@Override
public void onAuthFail(String error) {
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
}
After logging I have the second button-information
information.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Bundle params = new Bundle();
String accessToken = mFacebook.getAccessToken();
try
{
params.putString("format", "json");
params.putString("access_token", accessToken);
String url = "https://graph.facebook.com/me";
String response = Util.openUrl(url, "GET", params);
try{
JSONObject json = Util.parseJson(response);
String name = json.getString("name");
String fname = json.getString("first_name");
}
catch(FacebookError e){
e.printStackTrace();
}
}
catch(Exception e)
{
}
}
});
When pressed the button information I wanna retrieve the personal user information like name and first_name.
I tried to retrieve the user’s personal information by using this:
"https://graph.facebook.com/me".
But when I press the second button nothing happens.Can someone tell me where I’m going wrong?
Make sure you have downloaded the latest version. And when you have logged in and stored
AuthenticationTokento yourSharedPreferences.Then make a call to the
"me"usingrequest()function ofFacebookclass something like this.You have to just put
"me"String to the request, The remaining URL will be automatically added by theirUtilclass.