我创建了一个代码 swift,它使用 facebook SDK 4.x。该代码使用 FBSDKShareButton 并且运行良好。 这是代码:
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://alexandreccarmo.com")
content.contentTitle = "Teste"
content.contentDescription = "teste teste"
content.imageURL = NSURL(string: "xxxx/2.jpg")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 25)
self.view.addSubview(button)
但我需要在不使用 facebook 对话框的情况下分享。当用户点击我的应用程序按钮时,我需要直接在他们的 facebook 上分享。 我试过这个:
let contentx : FBSDKShareLinkContent = FBSDKShareLinkContent()
contentx.contentURL = NSURL(string: "http://alexandreccarmo.com")
contentx.contentTitle = "Testexxxxx"
contentx.contentDescription = "teste testexxx"
contentx.imageURL = NSURL(string: "xxxx/2.jpg")
FBSDKShareAPI.shareWithContent(contentx, delegate: nil)
但是我收到这个错误:
FacebookLogin[6721:3464359] FBSDKLog:警告:[FBSDKAccessToken currentAccessToken] 缺少 publish_actions 权限
我在 facebook 开发人员那里了解到,当我需要发送分享时,我需要请求“publish_actions”。但我不明白我该怎么做。有人知道吗?
最佳答案
下面是一些我用来在没有 Facebook SDK 的情况下在 Facebook 上发布图片的代码:
func actionTapped(sender: AnyObject) {
let objectsToShare = //reference to image
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.completionWithItemsHandler = actionCompleted
presentViewController(activityVC, animated: true, completion: nil)
}
func actionCompleted(activityType: String!, completed: Bool, returnedItems: [AnyObject]!, error: NSError!) {
// Return if cancelled
if (!completed) {
return
}
close()
}
您也可以查看这些链接:
- Can I use UIActivityViewController to share on Facebook ?
- http://roadfiresoftware.com/2014/02/how-to-add-facebook-and-twitter-sharing-to-an-ios-app/
- UIActivityViewController share only text
希望对您有所帮助。
关于ios - Swift - 直接在 facebook 上发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200914/