我正在使用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),有什麼建議?