0

我使用以下代码向图形 api 发送请求并将其显示在标签中

        [FBRequestConnection startWithGraphPath:@"40123148903?fields=picture" completionHandler:^(FBRequestConnection *connection, id<FBGraphObject> result, NSError *error)
         {
             if(!error)
             {
                  self.tryLabal.text = [[[result objectForKey:@"picture"] objectForKey:@"data"]objectForKey:@"url"];

             }
         }
         ];

问题是它只允许我使用块内的图形对象。我想保留返回的结果。

我尝试声明一个 id 属性并为其分配结果 id

self.tryGraphObject = result;

但这似乎不起作用。我究竟做错了什么?如何保存通话中的信息以备后用?

4

2 回答 2

0

you can use method from facebook delegate such as

  • (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {}
于 2012-11-19T14:28:05.100 回答
0

对不起。我的错。正确的方法是 - (void)request:(FBRequest *)request didLoad:(id)result

例子

请求
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];

response
- (void)request:(FBRequest *)request didLoad:(id)result {
//ok 所以它是一个包含一个元素 (key="data") 的字典,它是一个字典数组,每个字典都有 "name" 和"id" 键
项 = [[(NSDictionary *)result objectForKey:@"data"]retain];
for (int i=0; i<[items count]; i++) {
NSDictionary *friend = [items objectAtIndex:i];
long long fbid = [[friend objectForKey:@"id"]longLongValue];
NSString *name = [朋友 objectForKey:@"name"];
NSLog(@"id: %lld - 名称: %@", fbid, name);
}
}

于 2012-11-19T15:44:59.900 回答