如何使用Facebook图形API获取Facebook照片的源URL? [英] How do you get a Facebook photo's source URL using the facebook graph api?

查看:164
本文介绍了如何使用Facebook图形API获取Facebook照片的源URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我如何使用图形API来获取照片的源URL吗?因为我有照片ID,似乎我应该可以打电话来获取源URL。



作为我正在尝试做的一个例子,以下代码工作:

   - (IBAction)showPicture:(UIButton *)sender; 
{
//检索图片的代码

id path = @http://photos-e.ak.fbcdn.net/photos-ak-snc1/v5041/ 89 /40796308305分之51/ 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路径= [_facebook requestWithGraphPath:@98423808305 / sourceandDelegate:self]; ???






更新以包含请求didLoad方法

   - (void)请求:(FBRequest *)请求didLoad:(id)result { 


if([request.params objectForKey:@picture]){
//从结果中获取照片ID
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]];
}
};


解决方案

  requestWithGraphPath:@YOUR_PHOTO_IDandDelegate:self]; 

然后在请求响应中,您将获得有关图片的所有信息。见这里的一个例子:

https://graph.facebook.com/98423808305

抓取您所需的信息,可能会对关键的源,并按需要使用它。 http://developers.facebook.com/docs/reference/api/ 这是在FB开发过程中学习的好地方。

   - (void)request:(FBRequest *)request didLoad:(id)result {
NSLog %@,结果);
NSArray * keys = [result allKeys];
NSLog(@%@,keys);
NSString * imageURL = [result objectForKey:@source];
//这里可以使用此imageURL获取图像数据并在imageView中显示
}

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

   - (void)请求:(FBRequest *)请求didLoad:(id)result {
NSLog(@%@,result);
NSString * requestType = [request.url stringByReplacingOccurrencesOfString:@https://graph.facebook.com/withString:@];
if([requestType isEqualToString:@me]){
//请求获取用户的资料信息
}
else if([requestType isEqualToString:@me / picture ]){
//这是获取用户个人资料图片的请求
}
}

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


Could you tell me how to use graph api to get the source url for a photo? Because I have the photo id and it seems like I should be able to make a call to get the source 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. 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]; ???


Updated to include request didLoad method

- (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
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.

- (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.

这篇关于如何使用Facebook图形API获取Facebook照片的源URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆