I use this code in my apps to share Facebook pages:
class func shareWithDialog(viewController : UIViewController, delegate : FBSDKSharingDelegate, contentTitle: String, contentUrl: NSURL = url, contentDescription: String) {
let content = FBSDKShareLinkContent()
content.contentTitle = contentTitle
content.contentURL = contentUrl
content.contentDescription = contentDescription
let dialog = FBSDKShareDialog()
dialog.fromViewController = viewController
dialog.shareContent = content
dialog.mode = FBSDKShareDialogMode.FeedBrowser
dialog.delegate = delegate
dialog.show()
}
In the native code (above) FBSDKShareLinkContent.contentURL is set to the facebook page I want to share. I'm using Xamarin.Facebook.iOS.4.5.1.0 nuget package to add this functionality into a Xamarin app. The thing is that this SDK is similar to the native SDK but class ShareLinkContent doesn't have the property contentURL (it does have a ImageURL property).
I might be using the wrong class, but I could'n find the right class (other classes in the SDK are intended for sharing images and videos).
Thanks to Jason Steele I looked closer and see that contentUrl property was replaced by setContentURL() method. I used this method to point to the Facebook page I wanted to share and it worked.
It was a silly question after all ;)
Related
I'm sharing to Facebook with FB share dialog like this:
guard let localIdentifier = localIdentifier else {return}
let assetURL = "assets-library://asset/asset.MOV?id=" + localIdentifier + "&ext=MOV"
let video : FBSDKShareVideo = FBSDKShareVideo()
video.videoURL = URL(string:assetURL)
let content : FBSDKShareVideoContent = FBSDKShareVideoContent()
content.video = video
let shareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.delegate = self
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0 , execute: {
shareDialog.show()
})
I check that the url is valid. This is a local MOV file and I copy it first to the camera roll. Then I retrieve it using PHManager and trying to share with FBSDK share dialog.
The FB sharing dialog with the movie appears and I press post. The FB seems processes the file and I get a V - that probably the video was shared.Afterwards I get the callback the share was cancelled. Did somebody experience the same? What might be the problem?
Thanks in advance.
What version of the FacebookSDK are you using? I had this problem too and it was because the version that I was using was not compatible with iOS 11 yet. I think that from v 4.27 it's compatible, I was using v4.23. Hope it helps.
I have tried many ways to achieve this but failed.
I have to share info on facebook with a URL and when clicked on the url, it will redirect to my app's specific page.
step# 1
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: linkUrl) as URL!
content.contentTitle = "Test"
content.quote = "game"
content.contentDescription = "This is a test game to test Fb share functionality"
content.imageURL = NSURL(string: imgUrl) as URL!
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.native
dialog.fromViewController = vc
dialog.shareContent = content
// if you don't set this before canShow call, canShow would always return YES
if !dialog.canShow() {
// fallback presentation when there is no FB app
dialog.mode = FBSDKShareDialogMode.feedBrowser
}
dialog.show()
It is working and successfully sharing the post. When I clicked on the link, it is redirecting to the app, not much info to redirect to a particular ViewController.
Step# 2
let properties = [
"fb:app_id": "Fb_id",
"og:type": "article",
"og:title": "Test",
"og:description": "This is a test game to test Fb share functionality",
"og:image" : urlImg,
"og:url" : linkUrl,
]
let object : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject.init(properties: properties)
// Create an action
let action : FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
action.actionType = "news.publishes"
action.setObject(object, forKey: "article")
// Create the content
let content : FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "article"
FBSDKShareDialog.show(from: vc, with: content, delegate: nil)
Here I am using Open Graph to post and successfully posted the Info. But con't redirecting to my app when clicked the link.
NB:
I don't have web Application.
My goal is to share a post with a app link. When clicked on that link it will open the app and redirect to a specific page if app is installed, otherwise redirect to the AppStore. So what should be the link format or how can I build the link to achieve this functionality?
Please help.
Thanks in advance
Use Universal Links. If you want to achieve something like this using universal link is a good idea. You can redirect to a specific page in your app if the app is installed otherwise it will navigate to appstore.
Here is how to implement universal links if you are not aware of:
Set up universal links - Raywenderlich
Universal links - Appsflyer
Note: Please ignore this, if this is not what you are looking for
I managed to achieve the same result using Branch.io. It's a very powerful app routing SDK and their console practically guides you down the routing scheme in a very visual and understandable manner.
The way it works is by dynamically creating a webpage with certain redirecting features according to what you set in the dashboard. You can then use that generated webpage to share it on Facebook or anywhere else.
Here's how you can integrate it:
Create an account here
Install and link the SDK (pod 'Branch')
Set up the routing mechanism using Branch's dashboard (it's guided and pretty straightforward, you just fill in the branches below). You can always change how the diagram looks like (if you want to always end up on a website or so, for instance)
Initialize the share data in your app
let branchUniversalObject: BranchUniversalObject = BranchUniversalObject(canonicalIdentifier: "any ID here") // just for tracking count and analytics
branchUniversalObject.title = "some title" // This will appear as the shared content's title
branchUniversalObject.contentDescription = "some description" // This will appear as the shared content's description
branchUniversalObject.imageUrl = "www.example.com/test.png"
branchUniversalObject.addMetadataKey("uid", value: self.userId)
branchUniversalObject.addMetadataKey("otherInfo", value: self.otherInfo)
Generate link and share the link on Facebook
let linkProperties = BranchLinkProperties()
linkProperties.channel = "Facebook"
linkProperties.feature = "Share"
// generate link
branchUniversalObject.getShortUrl(with: linkProperties, andCallback: { (shareURL, error) in
if error != nil {
// handle error
}
// init Facebook share data
let content = FBSDKShareLinkContent()
content.contentTitle = "Some title"
content.contentURL = URL(string: shareURL) // this URL handles the redirecting according to your dashboard's settings
content.contentDescription = "Some description"
content.imageURL = URL(string: "www.example.com/test.png")
// create Facebook share dialog
let dialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = content
dialog.mode = .automatic
if dialog.canShow() {
dialog.show()
}
})
Yes, I achieved this functionality by setting up the metadata in the server end.
References: https://developers.facebook.com/docs/applinks
https://developers.facebook.com/docs/applinks/ios
Thanks...
I went through Branch.io's documentation a lot over the past few days and I can't seem to pinpoint the problem. I got the generated link to work properly by setting up the BranchUniversalObject as follows:
let branchUniversalObject: BranchUniversalObject = BranchUniversalObject(canonicalIdentifier: "ios_share_user")
branchUniversalObject.title = "My Title"
branchUniversalObject.contentDescription = "My Description"
branchUniversalObject.imageUrl = "www.example.com/image.jpg"
branchUniversalObject.addMetadataKey("id", value: self.userId)
branchUniversalObject.addMetadataKey("type", value: self.userType)
let linkProperties = BranchLinkProperties()
linkProperties.channel = "Facebook"
linkProperties.feature = "Share"
branchUniversalObject.getShortUrl(with: linkProperties, andCallback: { (shareURL, error) in
if error != nil {
print(error!)
return
}
// using shareURL here
})
The generated URL works perfectly fine, but only when launched from Notes or Messages apps. Safari always redirects me to the AppStore and so does the Facebook app when I try sharing the URL like this:
let content = FBSDKShareLinkContent()
content.contentTitle = "My Title"
content.contentURL = shareURL // generated above
content.contentDescription = "My Description"
content.imageURL = "www.example.com/image.jpg"
let dialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = content
if dialog.canShow() {
dialog.show()
}
That shows up the dialog and shares the content as intended, but the link always redirects me to the AppStore just like in Safari.
Here's a screenshot of the Dashboard:
I also have applinks:myLinkDomain.app.link and applinks:myLinkDomain-alternate.app.link in the Associated Domains, branch_app_domain = myLinkDomain.app.link along with branch_key = ["live": "key_live_myKey"] in Info.plist, and AppDelegate is properly set.
What am I missing to get the app to open from Safari and Facebook instead of getting redirected to the AppStore?
I'm deploying the app for iOS 9.3+
Thanks!
I came across this link and it shows that the problem isn't with Branch.io SDK's setup by any means, but a limitation imposed by Apple. The only workaround is using Branch's Deepviews, which unfortunately I can't use in my case.
Hope Branch.io figure out a way around that! ...And possibly update their documentation to clearly state that some app browsers are not supported
I would like to know if I can check if my content was actually shared in Facebook?
I'm using Facebook SDK 4.1.x and FBSDKShareButton
The user has to authorize my app in Facebook, so I have a FB access token.
And I have this method to test the Share button
func newShareButton(){
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com.br")
content.contentTitle = "Test title"
content.contentDescription = "Test description"
content.imageURL = NSURL(string: "https://www.google.com.br/images/nav_logo225.png")
shareButton.shareContent = content
}
Everything is working fine, but I can't figure it out how to get the response, if the user actually shared the content.
Is it possible? Do I have to use other method to get the result?
Thanks in advance!
I am sharing a Facebook post using FBSDKShareKit framework using FBSDKShareLinkContent. I am setting the content's imageURL to load an image for the post to be shared. The problem is, when I am sharing the post while on a mobile internet/3G connection, the link's image is not loading and shared on the post. Meanwhile, it is working fine when sharing the link while on a Wifi connection. To further illustrate, please refer to the screenshot below:
Screenshot: http://i.imgur.com/S2Z4Ddi.png?1
My apologies as I can't post images yet due to my reputation.
I am using the following code to make and share the content.
let content:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: linkURL)
content.contentTitle = nsTitle as! String
content.contentDescription = nsDesc as! String
content.imageURL = NSURL(string: imageURL)
let button:FBSDKShareButton = FBSDKShareButton()
button.frame = CGRectMake(0, 0, 0, 0)
button.shareContent = content
button.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
Any ideas?
Thanks in advance.
Tested with other devices, could just potentially be a factory defect on the iPhone6's 3G.
The testing is done by using 2 different SIM Cards on the same phone, same result. Meanwhile both SIM Cards are also tested on another device, different result. Speedtest is also done to check. both of which are comparable in speed.