我正在尝试使用executeasync获取facebook的全名,但显然请求需要更长的时间,这不允许我将全名发送到下一个活动,尽管内部打印工作正常,并且名称打印正确
这是我的代码片段:
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.d("Prova","primagetfbname");
AccessToken accessToken = AccessToken.getCurrentAccessToken();
Log.d("tokenfb",accessToken.getToken());
getFbName();
}
public void getFbName() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
Log.d("tokenfb",accessToken.getToken());
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
profile_name = object.getString("name");
Log.d("Profile name",profile_name);
}catch(JSONException e){
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name");
request.setParameters(parameters);
request.executeAsync();
Log.d("Prova", profile_name);
Intent intentFacebookinfo = new Intent(getApplicationContext(), FacebookLogin.class);
intentFacebookinfo.putExtra("FullName", profile_name);
Log.d("Prova", profile_name);
startActivity(intentFacebookinfo);
}
单击此处查看代码的完整图像
暂无答案!
目前还没有任何答案,快来回答吧!