0
我的FB請求輸出在iOS中不起作用。它輸出兩次到控制檯。第一次輸出正確的信息,然後立即用(空)代替正確的數據做同樣的事情。FB請求輸出在iOS中不起作用
這裏是我的代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:@"fbKEY....." andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
//FB check for valid session
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"user_location",
@"user_checkins",
// @"publish_actions",
// @"user_activities",
// @"friends_birthday",
nil];
[facebook authorize:permissions];
}
[facebook requestWithGraphPath:@"me" andDelegate:self];
// get the posts made by the "platform" page
[facebook requestWithGraphPath:@"platform/posts" andDelegate:self];
// get the logged-in user's friends
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
[facebook dialog:@"feed" andDelegate:self];
// Override point for customization after application launch.
return YES;
}
- (void)request:(FBRequest *)request didLoad:(id)result {
NSDictionary *userData = (NSDictionary *)result; // The result is a dictionary
NSString *name = [userData objectForKey:@"name"];
NSString *location = [[userData objectForKey:@"location"] objectForKey:@"name"];
NSString *gender = [userData objectForKey:@"gender"];
NSLog(@"name is %@", name);
NSLog(@"location is %@", location);
NSLog(@"gender is %@", gender);
// NSLog(@"%@",result);
}
,這裏是我的NSLog輸出:
2012-04-04 16:42:56.440 Whatto[86350:15803] name is John Doe
2012-04-04 16:42:56.441 appName[86350:15803] location is London
2012-04-04 16:42:56.441 appName[86350:15803] gender is male
2012-04-04 16:42:56.688 appName[86350:15803] name is (null)
2012-04-04 16:42:56.688 appName[86350:15803] location is (null)
2012-04-04 16:42:56.689 appName[86350:15803] gender is (null)
2012-04-04 16:42:58.696 appName[86350:15803] name is (null)
2012-04-04 16:42:58.697 appName[86350:15803] location is (null)
2012-04-04 16:42:58.697 appName[86350:15803] gender is (null)
感謝您的任何幫助
您必須展示更多代碼。特別是您創建請求的方法 – Zalykr 2012-04-04 15:50:16
我添加了didFinishLaunchingWithOptions方法。 – hanumanDev 2012-04-04 15:53:28
您是否真的嘗試過對'request didLoad'方法進行突破並檢查Facebook返回的內容?這可能會告訴你什麼問題是... – lxt 2012-04-04 15:55:07