I need to post a picture on the user's wall with a standard text. Can you do this with the FBSDK 4.x?
let photoshare = FBSDKSharePhoto(image: recortarImagem(), userGenerated: true)
let content = FBSDKSharePhotoContent()
content.photos = [photoshare]
let dialog = FBSDKShareDialog()
dialog.delegate = self
dialog.shareContent = content
dialog.fromViewController = self
dialog.mode = FBSDKShareDialogMode.ShareSheet
dialog.show()
As pointed out in the comments, this would violate the Platform Policy of Facebook (see 2.3, pre-filling at https://developers.facebook.com/policy/#control).
This being said, FBSDKSharePhoto has a field, caption that you can put a user-generated message in.
Related
I'm trying to share a photo to Messanger but it fails without returning any error.
But if I create a link instead of photo it works successfully.
photo.image = image
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKMessageDialog.show(with: content, delegate: nil)
I have a document's directory path of a gif I'd like to post to Facebook, but unfortunately when I use this process, it posts a static image instead of it being animated. I know it's animated because I can save the same image to my camera roll and see that it animates. Is there anyway of posting an animated version of this GIF?
let image = UIImage(contentsOfFile: path) // document directory path
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = image
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.mode = .native
shareDialog.show()
This is not as issue with your image due to Facebook natively not support gif image directly uploaded on it.
You can share gif image link on Facebook and it will show there gif image. Like as commonly peoples are using giphy, tenor website and share gif image link from this website. So gif image display via this type of website.
I hope this will help you.
UIWebView page that was opened by showing FBSDKAppInviteDialog doesn't load list of friends as usual, but stops either at an empty page state or at the infinite loading indicator state.
let text = "invite text"
content.appLinkURL = URL(string: "valid_url_to_fb_me")!
content.promotionText = text
content.promotionCode = "\(code)"
let dialog = FBSDKAppInviteDialog()
dialog.fromViewController = self.viewController
dialog.content = content
dialog.delegate = self
dialog.show()
And FBSDKAppInviteDialogDelegate methods were not called.
This behaviour was not reproducible a week ago.
iOS Simulator 10.2, same behaviour on the iOS 10.2.1 on real device the iPhone 5S and iPad mini 9.2.
Facebook SDK - 4.15.1
Thanks in advance for any help or sugestions.
the bug is on Facebook's side:
https://developers.facebook.com/bugs/721787828000962/
The Facebook bug mentioned by BoygeniusDexter (https://developers.facebook.com/bugs/721787828000962/) is actually on Android not iOS.
Are you using the deprecated UIActionSheet to open FBSDKAppInviteDialog? If so removing UIActionSheet is your solution: https://developers.facebook.com/bugs/172327909915305/
I have used the following code to capture a screenshot before using the image to post to Facebook:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(frame.size.width,frame.size.height), false, 0)
self.view?.drawViewHierarchyInRect(CGRectMake(-frame.origin.x, -frame.origin.y, view.bounds.size.width, view.bounds.size.height), afterScreenUpdates: false)
let screenShot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenShot
In the first instance I used the Social Framework and SLComposeViewController adding the screenshot with addImage. The image on the dialog box and ultimate post were perfect but this method does not allow you to choose your friends.
I then decided to use use FBSDKDialog as follows:
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = screenShot
photo.userGenerated = false
photo.caption = contentDescription
let photoContent : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
photoContent.contentURL = NSURL(string: self.contentURL)
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.shareContent = photoContent
shareDialog.delegate = self
if !shareDialog.canShow() {
shareDialog.mode = FBSDKShareDialogMode.Native
} else {
shareDialog.mode = FBSDKShareDialogMode.FeedBrowser
}
shareDialog.show()
The code works perfectly but the image quality on the share dialog box is extremely poor. Yet when I do make the post the image quality on the timeline is perfect.
I have tried to compress the image but nothing seems to make any difference.
Can anyone suggest what I am doing wrong?
Thank you.
You're not doing anything wrong. This is probably a way Facebook optimizes sharing.
I have the FBSDK sharing function working with the following code:
if (FBSDKAccessToken.currentAccessToken() != nil) {
// User is already logged in, do work such as go to
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: self.url_string)
content.contentTitle = self.title_text
content.contentDescription = self.desc_text
content.imageURL = NSURL(string: "http://image.png")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = self.view.center
self.view.addSubview(button)
}
The problem is that I don't have an imageURL, I have an image taken directly from the app's camera function stored as a UIImage variable. How can I attach an image to this FBSDKShareLinkContent without the image being hosted online? I'm using FBSDKShareLinkContent because I'm also sharing a link w/ title & description.
Edit, I'm trying FBSDKSharePhoto (as someone suggested) with this code, which lets me post the photo, but I can't get the URL to link properly even though content.contentURL is defined as it was before.
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = self.scaledImage
photo.userGenerated = true
let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
content.contentURL = NSURL(string: self.url_string)
content.photos = [photo]
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = CGPointMake(self.view.center.x, self.descLabel.center.y + 51 + 30) // 51 = 1/2 of height of descLabel, 30 = space below
self.view.addSubview(button)
Appears that the FBSDKSharePhotoContent is the way to go, but there is currently a bug that Facebook is aware of, which is causing the image & link to not work together.
https://developers.facebook.com/bugs/949486035103197/
They say this should be updated in the next Facebook app update v31. v30 was updated May 7 and FB releases updates every two weeks, so I'll check back in a week and confirm that the functionality is fixed.