【问题标题】:Swift - Publish directly on facebookSwift - 直接在 facebook 上发布
【发布时间】:2015-10-18 17:21:38
【问题描述】:

我创建了一个使用 facebook SDK 4.x 的 swift 代码。该代码使用 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”。但我不明白我该怎么做。有人知道吗?

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    下面是我用来在没有 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

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 2016-08-25
      • 1970-01-01
      • 2012-10-10
      相关资源
      最近更新 更多