ios - Swift - 直接在 facebook 上发布

标签 ios swift

我创建了一个代码 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()
}

您也可以查看这些链接:

  1. Can I use UIActivityViewController to share on Facebook ?
  2. http://roadfiresoftware.com/2014/02/how-to-add-facebook-and-twitter-sharing-to-an-ios-app/
  3. UIActivityViewController share only text

希望对您有所帮助。

关于ios - Swift - 直接在 facebook 上发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200914/

相关文章:

ios - tableview 在 section 方法中看不到标题的 tableview View

ios - NSFetchedResultsController performFetch 不起作用

android - 适用于 iOS/Android 的嵌入式浏览器应用程序

ios - 继续误解

ios - 在 swift 中的自定义 View 上播放透明视频(H.264,AAC)

swift - UITextField - 如果文本字段包含某些单词,则不发送到 firebase

swift - 没有科学记数法和四舍五入

ios - 基于 block 的动画不起作用 : Animations and Completion Blocks are Executed Immediately (Without Duration)

ios - Twitter在Cocos2d-iPhone中的集成

ios - 如何从 Swift 中的另一个类访问和刷新 UITableView