0

我正在设计一个应用程序,它使用 Facebook 在表格视图中显示提要..所以为了获得提要的结果,我调用了一个方法FBSDKGraphRequest但我不知道如何从外部的FBSDKGraphRequest检索结果的值因为它们位于完成块中。我想在表格视图中显示名称和消息....

代码说明如下:-

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:Path parameters:@{ @"fields": @"feed{from,message,created_time}",} tokenString:accessToken version:FBSDK_TARGET_PLATFORM_VERSION HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

    if(error)
        NSLog(@"No Data");

    else {
       FeedCount = [NSDictionary dictionaryWithDictionary:result];
       NSDictionary*feed = [FeedCount objectForKey:@"feed"];
       NSArray*array1 = [feed objectForKey:@"data"];
       NSArray*array3 = [array1 valueForKey:@"from"];
       NSLog(@"Data:%@",array3); ---------------> **Displaying Data**
         }
   }];
NSLog(@"FeedCount:%@",FeedCount);----------------->**Showing Null** 

任何帮助将不胜感激

4

1 回答 1

0

要从 fbsdk 获取字典结果,请将变量声明为__block NSDictionary *json;

然后分配这个内部块,例如,

json =[FeedCount objectForKey:@"feed"];

你试过这样吗,

__block NSDictionary *json;

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:Path parameters:@{ @"fields": @"feed{from,message,created_time}",} tokenString:accessToken version:FBSDK_TARGET_PLATFORM_VERSION HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

    if(error)
        NSLog(@"No Data");

    else {
       FeedCount = [NSDictionary dictionaryWithDictionary:result];
       json = [FeedCount objectForKey:@"feed"];
       NSArray*array1 = [feed objectForKey:@"data"];
       NSArray*array3 = [array1 valueForKey:@"from"];
       NSLog(@"Data:%@",array3); ---------------> **Displaying Data**
         }
   }];
NSLog(@"json:%@",json);
于 2015-12-24T08:51:27.183 回答