我想在android中获取我的facebook信息, 我的代码:
loginButton.setReadPermissions(Arrays.asList("email", "user_photos", "public_profile"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getApplicationContext(),""+loginResult.getAccessToken(),Toast.LENGTH_SHORT).show();
String accessToken = loginResult.getAccessToken().getToken();
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.i("LoginActivity", response.toString());
// Get facebook data from login
try {
object.get("gender");
object.get("email");
} catch (JSONException e) {
e.printStackTrace();
}
// Bundle bFacebookData = getFacebookData(object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, first_name, last_name, email,gender, birthday, location"); // Parámetros que pedimos a facebook
request.setParameters(parameters);
request.executeAsync();
}
但程序没有进入`public void onCompleted(JSONObject对象,GraphResponse响应){ 这个功能的结果是:
{Request: accessToken: {AccessToken token:ACCESS_TOKEN_REMOVED permissions:[email, user_photos, public_profile]}, graphPath: me, graphObject: null, httpMethod: GET, parameters: Bundle[{}]}
有什么解决方案吗?或者这个案例与facebook隐私设置有关?
答案 0 :(得分:1)
尝试手动构建登录流程。这样你就不会卡在sdk
上。
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
答案 1 :(得分:0)
尝试替换
loginResult.getAccessToken()
与
loginResult.getAccessToken().getToken() .
Facebook不允许开发人员直接记录“session.getAccessToken”,因为它可能会导致泄漏。还可以查看此信息以获取更多信息:http://stackoverflow.com/a/29544390/2754871