0

当我尝试加载我所有的 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"
)>}

知道我做错了什么吗?

4

2 回答 2

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);
    }
}];
于 2013-07-31T06:15:16.223 回答
0

查看我在 StackOverflow 中的答案,以获取具有自定义设计的 facebook 好友列表

如何在不打开 FBFriendPickerViewController iOS 的情况下获取好友列表

于 2013-07-31T05:35:46.473 回答