0

我的 FB 请求输出在 iOS 中不起作用。它向控制台输出两次。它第一次输出正确的信息,然后立即用 (null) 而不是正确的数据做同样的事情。

这是我的代码:

- (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)

谢谢你的帮助

4

1 回答 1

1

您正在提出 3 个不同的请求并将结果视为每个答案都是用户...第二个结果将是帖子列表,第三个结果将是朋友列表。

祝你好运!

于 2012-04-04T16:02:52.067 回答