如何使用Facebook SDK获取ID名称从Facebook的个人资料? [英] How to get id and name from facebook profile using facebook sdk?
本文介绍了如何使用Facebook SDK获取ID名称从Facebook的个人资料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道的方法是使用JSON和我读过很多关于如何做到这一点,但我仍然无法弄清楚在那里我必须把JSON code,所以我可以得到的ID和名称,因为一切我想没有工作(为空)。你们可以给我在那里我将要求标识和名称,这样我就可以真正得到他们的建议吗?
这一切都在我的主类与Facebook的:
I know that the way is using JSON and i have read much about how to do it, but i still can't figure out WHERE i have to put the JSON code so i can get the id and name, because everything i tried didn't work (was null). Can you guys give me an advice of where i shall request id and name so i can actually get them? This is everything in my main class related to facebook:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
this.facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}
@Override
protected void onResume() {
super.onResume();
updateLoginStatus();
}
public void updateLoginStatus() {
loginStatus.setText("Logged into Facebook as "+ facebookConnector.getUserName() + facebookConnector.getFacebook().isSessionValid());
}
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();
}
}
private void postMessageInThread() {
Thread t = new Thread() {
public void run() {
try {
facebookConnector.postMessageOnWall("test");
mFacebookHandler.post(mUpdateFacebookNotification);
} catch (Exception ex) {
Log.e(TAG, "Error sending msg",ex);
}
}
};
t.start();
}
private void clearCredentials() {
try {
facebookConnector.getFacebook().logout(getApplicationContext());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
最后,我想用
AsyncFacebookRunner myAsyncRunner = new AsyncFacebookRunner(facebook);
myAsyncRunner.request("me", new meRequestListener());
然后
public class meRequestListener implements RequestListener {
public void onComplete(String response, Object state) {
fbName = response;
}
当我得到与字符串
public String getUserName () {
return fbName;
}
它仍然是空。请帮助。
it is still null. Help please.
推荐答案
这是解决方案
String response = facebook.request("me", param, "GET");
希望它可以帮助别人谁也有类似的问题。
Hope it helps someone who had similar problem.
这篇关于如何使用Facebook SDK获取ID名称从Facebook的个人资料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文