[英]How do you get a Facebook photo's source URL using the facebook graph api?
Could you tell me how to use graph api to get the source url for a photo?你能告诉我如何使用图表 api 来获取源 url 的照片吗? Because I have the photo id and it seems like I should be able to make a call to get the source url.因为我有照片 ID,而且似乎我应该能够拨打电话以获取源 url。
As an example of what I'm trying to do, the following code works:作为我正在尝试做的一个示例,以下代码有效:
-(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];
}
However that works when I have the source url.但是,当我有源代码 url 时,它可以工作。 Is there a way to use graph api so that I can substitute id path = @"http://..."
for something like id path = [_facebook requestWithGraphPath:@"98423808305/source" andDelegate:self];
有没有办法使用图 api 以便我可以用id path = @"http://..."
代替id path = [_facebook requestWithGraphPath:@"98423808305/source" andDelegate:self];
??? ???
Updated to include request didLoad method更新为包括请求 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"]];
}
};
[_facebook requestWithGraphPath:@"YOUR_PHOTO_ID" andDelegate:self];
then in the request response you'll get every information about the picture.然后在请求响应中,您将获得有关图片的所有信息。 See an example here:在此处查看示例:
https://graph.facebook.com/98423808305 https://graph.facebook.com/98423808305
Grab your required info, might against the key "source", and use it as you want.获取您需要的信息,可能会针对关键“来源”,并根据需要使用它。 http://developers.facebook.com/docs/reference/api/ this is a very good place to learn while developing with FB. 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
}
Might this will give you idea how to sort different requests.这可能会让您了解如何对不同的请求进行排序。
- (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
}
}
Similarly you can sort different requests and hence perform different request specific tasks.同样,您可以对不同的请求进行排序,从而执行不同的请求特定任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.