0

你能告诉我如何使用graph api来获取照片的源url吗?因为我有照片 ID,而且似乎我应该能够拨打电话以获取源网址。

作为我正在尝试做的一个示例,以下代码有效:

-(IBAction)showPicture:(UIButton *)sender;
{
    //code to retrieve picture

    id path = @"http://photos-e.ak.fbcdn.net/photos-ak-snc1/v5041/89/51/40796308305/a40796308305_1960517_6704612.jpg";
    NSURL *url = [NSURL URLWithString:path];
    NSData  *data = [NSData dataWithContentsOfURL:url];
    UIImage *img = [[UIImage alloc] initWithData:data];
    [self.label setText: (NSString *)path];
    imageView.image = img;
    [img release];

}

但是,当我有源网址时,它会起作用。有没有办法使用图形 api,这样我就可以id path = @"http://..."代替id path = [_facebook requestWithGraphPath:@"98423808305/source" andDelegate:self];???


更新为包括请求 didLoad 方法

- (void)request:(FBRequest *)request didLoad:(id)result {


    if ([request.params objectForKey:@"picture"]) {
        // Get photo ID from result
        NSString *photoId = (NSString *)[result objectForKey:@"id"];
        shitStorm = photoId;
    }


  if ([result isKindOfClass:[NSArray class]]) {
    result = [result objectAtIndex:0];
  }
  if ([result objectForKey:@"owner"]) {
    [self.label setText:@"Photo upload Success"];
  } else {
    [self.label setText:[result objectForKey:@"name"]];
  }
};
4

1 回答 1

2
[_facebook requestWithGraphPath:@"YOUR_PHOTO_ID" andDelegate:self];  

然后在请求响应中,您将获得有关图片的所有信息。在此处查看示例:
https:
//graph.facebook.com/98423808305 获取您所需的信息,可能针对关键“来源”,并根据需要使用它。http://developers.facebook.com/docs/reference/api/这是使用 FB 开发时学习的好地方。

- (void)request:(FBRequest*)request didLoad:(id)result {  
    NSLog(@"%@",result);
    NSArray *keys=[result allKeys];
    NSLog(@"%@",keys);
    NSString *imageURL=[result objectForKey:@"source"];
    //here you can use this imageURL to get image-data and display it in imageView  
}  

这可能会让您了解如何对不同的请求进行排序。

- (void)request:(FBRequest*)request didLoad:(id)result{
    NSLog(@"%@",result);
    NSString *requestType =[request.url stringByReplacingOccurrencesOfString:@"https://graph.facebook.com/" withString:@""];
    if ([requestType isEqualToString:@"me"]) {
        //Request to get User's Profile info
    }
    else if ([requestType isEqualToString:@"me/picture"]) {
        //this is the request to get User's Profile Picture
    }   
}  

同样,您可以对不同的请求进行排序,从而执行不同的请求特定任务。

于 2011-07-07T16:00:10.113 回答