当我尝试加载我的所有Facebook好友时,我得到了一个时间请求超时错误。
我有FBSessionOpen状态。 我的代码:
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id data, NSError *error) {
if(error) {
NSLog(@"Error: %@", error);
[self.delegate didFinishLoadingFriendsWithResult:[ErrorResponse errorResponseWithMessage:@"Failed to load user friends from Facebook"] succes:NO];
return;
}
NSArray* friends = (NSArray*)[data data];
NSLog(@"You have %d friends", [friends count]);
NSLog(@"Friends: %@", friends);
[self.delegate didFinishLoadingFriendsWithResult:friends succes:YES];
}];
错误讯息:
Error: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1d1e3a30 {com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1d1e16a0 {NSErrorFailingURLStringKey=https://graph.facebook.com/me/friends?sdk=ios&fields=id%2Cname%2Cusername%2Cfirst_name%2Clast_name&migration_bundle=fbsdk%3A20130120&format=json&access_token=CAAHyDtIdIi0BAM6ZCtXb3Yb5jzuPQ7Tvc6mYg1zO1ZBjoEqZBI5sB5eFYQiTp6s0euVhMTQcl1yqXnaLT118BIBaaEtY1hLEpKq1ptG6y4dHR8BknAOTZCpRUvYlJlT6KbL42MXk2VaMZBvGRwIvs1644FSxy5vVRBSTIFsNZAzIyRpQjjhIA1, NSErrorFailingURLKey=https://graph.facebook.com/me/friends?sdk=ios&fields=id%2Cname%2Cusername%2Cfirst_name%2Clast_name&migration_bundle=fbsdk%3A20130120&format=json&access_token=CAAHyDtIdIi0BAM6ZCtXb3Yb5jzuPQ7Tvc6mYg1zO1ZBjoEqZBI5sB5eFYQiTp6s0euVhMTQcl1yqXnaLT118BIBaaEtY1hLEpKq1ptG6y4dHR8BknAOTZCpRUvYlJlT6KbL42MXk2VaMZBvGRwIvs1644FSxy5vVRBSTIFsNZAzIyRpQjjhIA1, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1d1e3800 "The request timed out."}, com.facebook.sdk:HTTPStatusCode=200, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x1d1b0c90, state: FBSessionStateOpen, loginHandler: 0x1d1b0db0, appID: 547620445299245, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x1d1afdd0>, expirationDate: 2013-09-28 09:49:39 +0000, refreshDate: 2013-07-30 14:08:31 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
"read_friendlists"
)>}
知道我做错了吗?
答案 0 :(得分:1)
看起来你刚才没有要求Facebook获得所需的许可。只需使用
[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObjects:@"read_friendlists", @"user_status", @"friends_status", nil] allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session state:status error:error];
}];
然后
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
friendsRequest.session = FBSession.activeSession;
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends", friends.count);
NSLog(@"friends: %@", result);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}];
答案 1 :(得分:0)
在StackOverflow中查看我的答案,获取具有自定义设计的facebook好友列表
How to get the list of friend without opening FBFriendPickerViewController iOS