FB请求输出在iOS中不起作用

时间:2012-04-04 15:47:03

标签: objective-c ios facebook-graph-api

我的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)

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

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

祝你好运!