2014-05-05 110 views
1

我正在使用Facebook SDK 3.14(最新),一切工作正常。然後,昨天,它停止顯示登錄用戶的朋友列表。Facebook好友列表突然返回null

這裏的時候我就logIn點擊buttonL

- (IBAction)buttonClickHandler:(id)sender { 
// get the app delegate so that we can access the session property 
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

// this button's job is to flip-flop the session from open to closed 
if (appDelegate.session.isOpen) { 
    // if a user logs out explicitly, we delete any cached token information, and next 
    // time they run the applicaiton they will be presented with log in UX again; most 
    // users will simply close the app or switch away, without logging out; this will 
    // cause the implicit cached-token login to occur on next launch of the application 
    [appDelegate.session closeAndClearTokenInformation]; 

} else { 
    if (appDelegate.session.state != FBSessionStateCreated) { 
     // Create a new, logged out session. 
     appDelegate.session = [[FBSession alloc] init]; 
    } 

    // Attempt to open the session. If the session is not open, show the user the Facebook login UX 

    // if the session isn't open, let's open it now and present the login UX to the user 
    [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                FBSessionState status, 
                NSError *error) { 
     // and here we make sure to update our UX according to the new session state 
     [self updateView]; 
    }]; 

} 

}

而在updateView方法,我呼籲Facebook的圖形請求的JSON:

- (void)updateView { 
// get the app delegate, so that we can reference the session property 
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 
if (appDelegate.session.isOpen) { 
    // valid account UI is shown whenever the session is open 

    selectedPageURL=[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=name,id,picture,gender", 
        appDelegate.session.accessTokenData.accessToken]; 

    [self load_HTTPRequest:selectedPageURL]; 

    [FBSession setActiveSession:appDelegate.session]; 
    FBRequest *me = [FBRequest requestForMe]; 
    [me startWithCompletionHandler:^(FBRequestConnection *connection, 
            id result, 
            NSError *error) { 
     NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result; 

     self.name.text = my.name; 
     [self.profile setImageWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [my id]] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]]; 
    }]; 

而在AppDelegate,這就是我包括的內容:

- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 
    // attempt to extract a token from the url 
    return [FBAppCall handleOpenURL:url 
        sourceApplication:sourceApplication 
         withSession:self.session]; 
} 

這些做得很好,但突然朋友列表爲空(Empty Json),有什麼建議?

回答

1

我認爲這是因爲最後的Facebook SDK只返回我們的朋友,允許應用程序訪問他們的個人資料信息。因此,我們的朋友列表將只返回在請求之前允許應用程序的朋友。

正如你可以看到下面的權限來訪問我們的好友列表:

「權限

與user_friends權限的用戶訪問令牌,查看當前人的朋友需要 這隻會返回任何朋友誰已經使用(通過Facebook登錄)提出請求的應用程序。「

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends/

0

即使Facebook的Android移動應用本身是顯示同樣的錯誤。

似乎Facebook在他們的API中有一個錯誤。

  1. Goto任何人的個人資料。
  2. 點擊「朋友」鏈接。
  3. 您會看到一個顯示「瞭解null的朋友」的新窗口。