Send image and text with OpenGraph FacebookSDK 4.4 in Swift

Hi all,


I am working with Facebook SDK 4.4.0 in my Swift App. Because Facebook forced the removal of prefilled text, I am trying to use Open Graph to post on Facebook content and image from my app.

What I need to do is to send to the Facebook Timeline some text content and also a local image (not on the web). The image is local so it is within the app.

What I achieved until now is to send the local image OR the content, but I want to send both things together.


Here is the Swift code to send the image that works:

@IBAction func facebookButton(sender: UIButton) {
    let photo : FBSDKSharePhoto = FBSDKSharePhoto()
    photo.image = UIImage(named: oldImageSaved! as String)
    photo.userGenerated = false


    var content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
    content.photos = [photo]


    let button:FBSDKShareButton = FBSDKShareButton()
    button.frame = CGRectMake(0, 0, 0, 0)
    button.shareContent = content
    button.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
}


And here is the OpenGraph code, that works, to send the content:

@IBAction func facebookButton(sender: UIButton) {


        var current = NSUserDefaults.standardUserDefaults().objectForKey("currentPhrase") as? String
        var currentDescription = current!
        let ImageSaved = NSUserDefaults.standardUserDefaults().objectForKey("currentImageSaved") as? NSString


        // Create a FBSDKSharePhoto
        var photo : FBSDKSharePhoto = FBSDKSharePhoto()
        photo.image = UIImage(named: ImageSaved! as String)
        photo.userGenerated = false;


        let graphProperties : [NSObject : AnyObject]! = ["og:type": "fbtestapp:testing_test_app", "og:title":"Test App", "og:description": currentDescription]
        var graphObject : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: graphProperties)


        // Create an action
        var action : FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()


        action.actionType = "fbtestapp:merging"
        action.setObject(graphObject, forKey: "testing_test_app")


        // Create the content
        var content : FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
        content.action = action;
        content.previewPropertyName = "testing_test_app";


        FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
}


Any help on how can I send local image with some text content with OpenGraph in Swift will be really appreciated!

Hey,

I have been trying to do the same thing but with no success. have you been able to figure this out? I have been able to send text, text with an image from a web site but not an image from the phone. I hope one of us can get this working.

Let me know what you come up with.

Thanks.

Kurt

I've been making the same attempt, but I've had no luck. Have you managed to solve this yet? I can transmit text, text that includes an image from a website, but not text that includes a picture from my phone. I'm hoping that one of us can make this work.

Please share your ideas with me.

Send image and text with OpenGraph FacebookSDK 4.4 in Swift
 
 
Q