我在Stack Overflow上看到了很多类似的问题,但它们没有解决我的问题。我参考了这个,这个以及文档链接,如这个和这个。
我在LogCat中看到了这个信息:
我在我的应用中使用LoginButton
登录。
我能够使用以下代码获取已登录用户的名称、电子邮件等信息(它可以正常工作):
private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
email = object.getString("email");
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("EMAIL",email);
Log.e("GraphResponse", "-------------" + response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,link,gender,birthday,email");
request.setParameters(parameters);
request.executeAsync();
}
涉及权限:
loginButton.setReadPermissions("user_friends");
loginButton.registerCallback(callbackManager, callback);
我在日志中得到了 JSON。但现在我想要获取 好友列表,因此我查看了 文档 并稍微修改了一下我的代码:
private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
// I saw following code in Documentation
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{friendlist-id}", /* I actually tried ,friend-list-id' , /me/friends' , '/me/taggable_Friends' and many*/
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
// handle the result
Log.d("RESPONSE KBT",response.toString());
}
}
).executeAsync();
}
带有权限:
loginButton.setReadPermissions(Arrays.asList("email", "user_friends","read_custom_friendlists"));
loginButton.registerCallback(callbackManager, callback);
我在LogCat中看到了这个信息:
RESPONSE KBT﹕ {Response: responseCode: 404, graphObject: null, error: {HttpStatus: 404, errorCode: 803, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: {friendlist-id}}}