我在我的应用程序中使用facebook集成登录。我使用了facebook SDK 4.2。一切正常。按下登录按钮后,Facebook会提示登录,然后是权限页面。但是一旦我给予许可,没有回拨是在代码中调用,即使提供了权限,因为我可以在我的facebook帐户中查看.Below是回调代码
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
loginButton = (LoginButton) getView().findViewById(R.id.connectWithFbButton);
loginButton.setCompoundDrawablePadding(50);
List<String> permissionNeeds = Arrays.asList("user_photos", "email", "user_birthday", "public_profile");
loginButton.setReadPermissions(permissionNeeds);
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess");
Log.v("LoginActivity", "onSuccess");
AccessToken token = loginResult.getAccessToken();
GraphRequest request = GraphRequest.newMeRequest
(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Application code
// Log.v("LoginActivity", response.toString());
System.out.println("Check: " + response.toString());
try {
String id = object.getString("id");
String name = object.getString("name");
String email = object.getString("email");
String gender = object.getString("gender");
String birthday = object.getString("birthday");
Toast.makeText(getActivity(), "Logged In", Toast.LENGTH_SHORT);
System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + 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");
}
});
}`
我也覆盖了onActivityResult();
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
请建议任何解决方案?
注意:我在片段
中使用了这段代码答案 0 :(得分:0)
我发现解决方案.FB回调没有进入片段。当我移动整个代码时,活动回调开始被调用。它在片段内部不起作用。