[英]Facebook sdk getting friends using my app
I'm trying to get my friends using the same application that I'm using, I wrote the following code: 我试图让我的朋友使用与我使用的相同的应用程序,我编写了以下代码:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.d("-@-", "graph response " + response.getJSONObject());
}
}
).executeAsync();
It's giving in the logcat the following error : 它在logcat中给出以下错误:
09-14 21:05:10.096: W/FacebookSDK.Request(12520): starting with Graph API v2.4, GET requests for //me/friends should contain an explicit "fields" parameter.
Also the output in the log is : 日志中的输出也是:
09-14 21:05:10.706: D/-@-(12520): graph response {"summary":{"total_count":776},"data":[]}
Any help please ? 有什么帮助吗?
Try to: 尝试:
private void getUserFriendsFacebookIds() {
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.d("-@-", "graph response " + response.getJSONObject());
if (response.getError() != null) {
Log.e(TAG, "User data error: " + response.getError(), response.getError().getException());
} else {
setUserFriends(response.getRawResponse());
}
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name");
request.setParameters(parameters);
request.executeAsync();
}
private void setUserFriends(String json) {
FacebookFriendsInfo ff = new Gson().fromJson(json, FacebookFriendsInfo.class);
Log.i(TAG, "User friends: " + ff);
...
}
To parse response try to use GSON library. 要解析响应,请尝试使用GSON库。
public class FacebookFriendsInfo {
public List<Friend> data = new ArrayList<Friend>();
public String getIds() {
StringBuilder sb = new StringBuilder();
for (Friend f : data) {
sb.append(String.format("%d,", f.id));
}
return sb.toString();
}
@Override
public String toString() {
return "FacebookFriendsInfo{" +
"data=" + data +
'}';
}
public class Friend {
public long id;
public String name;
@Override
public String toString() {
return "Friend{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
}
Try with this API call: me/friends?fields=name
尝试使用以下API调用: me/friends?fields=name
See "Declarative Fields" in the changelog for v2.4: https://developers.facebook.com/docs/apps/changelog#v2_4 请参阅v2.4的变更日志中的“声明性字段”: https : //developers.facebook.com/docs/apps/changelog#v2_4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.