0

グラフAPIを使用して写真のソースURLを取得する方法を教えてください。私は写真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];

}

ただし、ソースURLがある場合は機能します。グラフ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 に答える