尝试获取Facebook好友列表以填充Spinner对象。实际上我似乎根本无法获取好友列表并且一直在挖掘所有地方以使其工作。使用早期的代码,我试图让事情没有运气。任何帮助都会非常感激。下面是与此相关的代码片段!目前我甚至没有尝试填充旋转器,因为我似乎没有得到我需要的东西。我的名单朋友最终没有任何内容可以填充微调器。
Bundle extras = getIntent().getExtras();
if (extras != null) {
Session s = (Session) extras.getSerializable("facebookSession");
if ((s!= null && s.isOpened()))
{
Log.d("FacebookSession", " is not null and is open");
}
else if ((s != null && !s.isOpened()))
{
Log.d("FacebookSession", " is not null and is not open");
}
else if (!(s != null))
{
Log.d("FacebookSession", " is null");
}
Session.setActiveSession((Session) extras.getSerializable("facebookSession"));
Session session = Session.getActiveSession();
SessionState state;
boolean i = session != null && session.isOpened();
String l;
if (i) { l = "true"; }
else { l = "false"; }
Log.d("Logged in", l);
if (i)
{
Log.d("tagging", "trying to get data");
getUserData(session, session.getState());
requestMyAppFacebookFriends(session);
}
}
会话有效,最终可以在我的getUserData函数调用中填充用户ID和个人资料照片。
private Request createRequest(Session session) {
Request request = Request.newGraphPathRequest(session, "me/friends", null);
Set<String> fields = new HashSet<String>();
String[] requiredFields = new String[] { "id", "name", "picture"};
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
private void requestMyAppFacebookFriends(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
List<GraphUser> friends = getResults(response);
// TODO: your code here
int x = friends.size();
Log.i("List of Friends size -> ", "" + x);
}
});
friendsRequest.executeAsync();
}
private List<GraphUser> getResults(Response response) {
GraphMultiResult multiResult = response
.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
Log.i(“朋友名单大小 - &gt;”,“”+ x);输出以记录cat size zero
11-12 03:22:37.352 4300-4300/mobileapps.*************** I/List of Friends size ->﹕ 0
请帮忙
答案 0 :(得分:1)
根据新的Facebook API,除非朋友授权您的应用,否则无法获取好友列表。只有当使用旧版本的Facebook API / sdk时,仍然可以检索朋友列表。希望这有帮助..我能够使用旧版本的facebook apis成功列出我的朋友..