将图像发布到相册中。 iOS 参考的 Facebook SDK (v4.0.1)

Posting image into an album. Facebook SDK for iOS Reference (v4.0.1)

我想将图片上传到我已经在 Facebook 上创建的特定相册。

我有相册ID。我是用旧的 API (https://developers.facebook.com/docs/graph-api/reference/v2.3/album) 做的,但我找不到任何方法用新的做。

我目前正在 post 与

合影
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
            photo.image = [UIImage imageWithData:attachment.data];
            photo.userGenerated = YES;
            FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
            content.photos = @[photo];
            [FBSDKShareAPI shareWithContent:content delegate:nil];

此外,我想post对照片进行描述。

有什么办法吗?

谢谢!

您必须自己创建 FBSDKShareAPI,而不是使用便捷方法。

这对我有用:

FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageWithData:attachment.data];
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
FBSDKShareAPI *shareObject = [[FBSDKShareAPI alloc] init];
shareObject.shareContent = content;
shareObject.graphNode = [NSString stringWithFormat:@"/%@/photos", FB_ALBUM_ID];
[shareObject share];

其中 FB_ALBUM_ID 是您要上传到的相册的 Facebook 图 ID。

Swift版本:

let photo = FBSDKSharePhoto()
photo.image = image
photo.isUserGenerated = true

let content = FBSDKSharePhotoContent()
content.photos = [photo]

let shareObject = FBSDKShareAPI()
shareObject.shareContent = content
shareObject.graphNode = String(format:"/%@/photos", facebookAlbumId) 
shareObject.share()

顺便说一句,如果你需要一个委托,你可以在 shareObject 上设置它