使用FBSDKShareButton将图像上传到Facebook

时间:2016-04-22 16:01:15

标签: ios swift facebook

我看了FacebookSDKhttps://developers.facebook.com/docs/sharing/ios/send-button,我只看到要上传到Facebook的imageURL。

NSURL *contentURL = [[NSURL alloc] initWithString:
  @"http://en.wikipedia.org/wiki/Facebook"];

NSURL *imageURL = 
  [NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];

_sendButton.shareContent = [[FBSDKShareLinkContent alloc]
  initWithContentURL: contentURL
  contentTitle: @"My Share Title"
  contentDescription: @"Lorem ipsum dolor sit amet."
  imageURL: imageURL
  peopleIDs: nil
  placeID: nil
  ref: nil
];

我尝试了shareButton

let shareButton = FBSDKShareButton()
        shareButton.center = view.center
        let content = FBSDKShareLinkContent()
        content.contentTitle = caption
        content.imageURL = NSURL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg")
        shareButton.shareContent = content
        view.addSubview(shareButton)

我可以轻松地将其上传到我的时间线。

但我只想发送从PhotoLibrary获取的图像上传到Facebook。是可能的,因为当我尝试content.image时(我没有暗示这个)

1 个答案:

答案 0 :(得分:1)

您正在使用FBSDKShareLinkContent,它只允许您共享链接(和img urls)。如果要将照片分享到Facebook,则需要使用FBSDKSharePhotoContent或FBSDKShareMediaContent类,您可以在其中添加UIImage对象数组。

请参阅SDK随附的目录示例应用,了解如何在实践中使用此功能。