2

I created a code swift, that use facebook SDK 4.x. The code use FBSDKShareButton and worked very well. This is the code:

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)

But I need to share without use facebook dialog. When the user click on button of my app I need share directly on their facebook. I tried this:

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)

But I receive this error:

FacebookLogin[6721:3464359] FBSDKLog: Warning: [FBSDKAccessToken currentAccessToken] is missing publish_actions permissions

I read on facebook developers that I need to request "publish_actions" when I need to send share. But I don't understand how can i do this. Somebody knows?

1 Answers1

1

So here is some code that I used to publish an image on Facebook without the Facebook SDK:

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()
}

You can check out these links as well:

  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

I hope this helps.

Community
  • 1
  • 1
Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95