0

你能告訴我如何使用圖形API來獲取照片的源網址嗎?因爲我有照片ID,所以我應該可以打電話來獲取源網址。如何使用臉譜圖API獲取Facebook照片的源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"]]; 
    } 
}; 

回答

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 
    } 
} 

同樣,您可以對不同的請求進行排序,從而執行不同的請求特定任務。

+0

嗨Admed,感謝您的回覆 - 我們都使用相同的FB例子。不過我理解請求響應的樣子。我不明白如何獲取所需的信息。因此,使用你的榜樣,我會做這樣的事情'ID路徑= [_facebook requestWithGraphPath:@ 「YOUR_PHOTO_ID」 andDelegate:自我 「];其次NSURL * URL = [NSURL URLWithString:[(的NSString *)[路徑objectForKey:@」 源「]]]?'...這是你告訴我做 – NateHill

+0

沒有NateHill你需要實現fbRequestDelegateProtocol ..在它的requestdidload方法,我想,你會得到所需要的數據的響應很可能是字典格式,你應該NSLOG所有你收到的答覆,以獲得更好的理解,告訴我,如果有幫助,或者我會嘗試把一些示例代碼。 – Ahmed

+0

這樣的幫助。我包含了我的請求didLoad方法,所以如果你可以使用它作爲你的例子,那將會很棒,我猜我對「代碼」應該在哪裏感到困惑,在我的showPicture方法中,我只是調用'[_facebook requestWithGraphPath:@ 「YOUR_PHOTO_ID」和Delegate:self「]',然後在我的請求中didLoad方法我把實際的代碼加載UIImage視圖?如果是這樣,該方法如何知道什麼時候該做什麼? – NateHill

相關問題