iOS - 如何使用FBGraph API从我的应用程序“喜欢/分享”特定页面的任何照片?

时间:2012-09-19 05:36:32

标签: iphone ios facebook facebook-like fb-graph

我正在使用FBGraph API将FaceBook集成到我的iOS应用程序中,我想从特定页面的相册或朋友的相册中“喜欢/分享”照片。可能吗?任何人都能帮助我吗?

1 个答案:

答案 0 :(得分:3)

试试这可能对你有帮助。
在post action方法中编写以下代码来共享照片。

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];
NSURL *imageURL = [[NSURL alloc]  initWithString:@"http://track_images/images/20120209104734baby-puppy.jpg"];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
UIImage *picture = [UIImage imageWithData:imageData];    
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:@"file"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"117795728310/photos" withPostVars:variables];
NSString *res = fb_graph_response.htmlResponse;
NSLog(@"res>> %@",res);
NSRange wordRange = NSMakeRange(0,2);
NSArray *firstWords = [[res componentsSeparatedByString:@"\""] subarrayWithRange:wordRange];

if (![[firstWords objectAtIndex:1] isEqualToString:@"error"]){
 //alert for image posted sucessfully. 
 }
 else{
 //alert for image not posted sucessfully.

}