您能告诉我如何使用图形API来获取照片的源网址吗?因为我有照片ID,看起来我应该能够打电话来获取源URL。
作为我正在尝试做的一个例子,以下代码有效:
-(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"]];
}
};
答案 0 :(得分: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
}
}
同样,您可以对不同的请求进行排序,从而执行不同的请求特定任务。