Post

Replies

Boosts

Views

Activity

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!
2
0
2.8k
Nov ’22