我设法在我的iPhone应用程序上实现Facebook连接,并允许用户通过应用程序上传状态更新。我现在想要包含一项功能,允许上传照片以及标题或状态更新。有谁知道相关的代码吗?
我想我应该在FB中使用photos.upload API,但我不太清楚如何。 Facebook文档似乎都非常通用,没有针对iPhone开发的特定代码。任何帮助或示例代码都值得赞赏。
答案 0 :(得分:10)
以下代码段取自facebook-ios-sdk。假设您的类已经有一个facebook对象,此方法将从URL上传照片(根据需要进行更改):
-(IBAction) uploadPhoto: (id)sender {
NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
[facebook requestWithMethodName: @"photos.upload"
andParams: params
andHttpMethod: @"POST"
andDelegate: self];
[img release];
}
要为照片发送标题,您必须添加“消息”参数键,然后添加标题文本。如下所示更改params
应达到此目的:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
@"my photo's caption text here.", @"message"
nil];
答案 1 :(得分:0)
您可以使用iOS Facebook SDK上传照片,如下所示:
FBSDKSharePhoto *photo=[[FBSDKSharePhoto alloc]init];
photo.image=slideImage;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
This works only if you configure iPhone Facebook settings.