0

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

4

1 回答 1

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.

}
于 2012-09-19T08:11:56.680 回答