本文介绍了Facebook registerCallBack方法未启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码通过我的Android应用程序获取Facebook用户详细信息。

I'm using the following code for fetching facebook user details through my android application.

 callbackManager = CallbackManager.Factory.create();

 fb = (Button) findViewById(R.id.fb);
 loginButton = (LoginButton) findViewById(R.id.login_button);

  List < String > permissionNeeds = Arrays.asList("user_photos", "email",
   "user_birthday", "public_profile", "AccessToken");
  loginButton.registerCallback(callbackManager,
  new FacebookCallback < LoginResult > () {@Override
      public void onSuccess(LoginResult loginResult) {

    System.out.println("onSuccess");

    String accessToken = loginResult.getAccessToken()
        .getToken();
    Log.i("accessToken", accessToken);

    GraphRequest request = GraphRequest.newMeRequest(
    loginResult.getAccessToken(),
    new GraphRequest.GraphJSONObjectCallback() {@Override
        public void onCompleted(JSONObject object,
        GraphResponse response) {

            Log.i("LoginActivity",
            response.toString());
            try {
                id = object.getString("id");
                try {

                    Log.i("profile_pic",
                    profile_pic + "");

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                name = object.getString("name");
                email = object.getString("email");
                gender = object.getString("gender");
                birthday = object.getString("birthday");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields",
        "id,name,email,gender, birthday");
    request.setParameters(parameters);
    request.executeAsync();
}

@Override
public void onCancel() {
    System.out.println("onCancel");
}

@Override
public void onError(FacebookException exception) {
    System.out.println("onError");
    Log.v("LoginActivity", exception.getCause().toString());
}
   });

@Override
protected void onActivityResult
(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
callbackManager.onActivityResult(requestCode,resultCode,data);
Log.i(onActivityResult,onActivityResult);

@Override protected void onActivityResult (int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); Log.i("onActivityResult", "onActivityResult");

}

这里打印onActivityResult中的日志,而loginButton.registerCallback(callbackManager,new FacebookCallback
任何人都可以帮我解决问题吗?

Here the log inside the onActivityResult is printed, while the loginButton.registerCallback(callbackManager, new FacebookCallback() is not at all initiated. None of the log's inside this method is printed.Can anyone please help me what the problem is???

推荐答案

只是通过在setContentView()上面放置callbackManager = CallbackManager.Factory.create();来解决问题;

I just solved the problem by placing "callbackManager = CallbackManager.Factory.create();" above the setContentView();

这篇关于Facebook registerCallBack方法未启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 07:52