Error when Facebook Open Graph Action shared from iOS (unsafe link) - ios

I tried to share a Facebook Open Graph Action via official iOS SDK (last version) but for a few days now, this action returns an error and it has now stopped working.
The app passed the Facebook approval, including actions and related objects and it all seems correct.
Object creation and share action
// ############## OpenGraph - Arrive At a Marina
// Photo
var photoURL = ""
if let image = firstMarina.images.first {
photoURL = image.width1440
} else {
photoURL = "https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
}
let photo = FBSDKSharePhoto(imageURL: NSURL(string: photoURL)!, userGenerated: false)
// Properties
let properties = [
"fb:app_id": "xxxxxxxxxxxxxxxxxxxxx",
"og:locale": NSLocale.preferredLanguages()[0].stringByReplacingOccurrencesOfString("-", withString: "_"),
"og:type": "smartsea:marina",
"og:title": firstMarina.name!.text,
"og:description": firstMarina.desc!.text,
"og:image": [photo],
"place:location:latitude": firstMarina.location!.lat,
"place:location:longitude": firstMarina.location!.lng
]
// Object
let object = FBSDKShareOpenGraphObject(properties: properties as [NSObject : AnyObject])
// Action
let action = FBSDKShareOpenGraphAction(type: "smartsea:arrive_at", object: object, key: "marina")
// Content
let content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "marina"
// Share
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)
and the error returned
Error Domain=com.facebook.Facebook.platform Code=102 "(null)" UserInfo={error_reason=The content you're trying to share includes a link that our security systems detected to be unsafe:
https://m.facebook.com/appcenter/smartsea?fbs=9909&fb_object_id=1684374595135519
Please remove this link to continue., error_description=An error occurred during publishing., app_id=xxxxxxxxxxxxxxxxxxxxx, error_code=102}
The strange thing is that the error URL is a Facebook domain and I haven't share it this URL directly. It seems to be generated with every share action.
Any idea?
Thanks!

Unfortunately I can't post a simple comment, so I have to post it as an 'answer'. I have found this article. It's about blocked URLs, but unfortunately not about blocked 'Facebook' URLs. I hope it can help.
http://www.technerves.com/2015/07/unblock-your-website-url-from-facebook.html

It connection might be getting blocked due to App transport security. App transport security is a new thing introduced in iOS9.
It blocks connections to servers that don't meet certain security requirements, such as minimum TLS version etc
Please try again after turning ATS OFF from info.plist. See this link which shows how to turn ATS OFF.

Related

iOS failing share on facebook

Client requirements are i have to share Image with Description , as per current facebook policies i can't share image with description so I am using
FBSDKShareOpenGraphObject
Following is my code
let ph = FBSDKSharePhoto(image: UIImage(named:"testimage"), userGenerated: true)
//These properties you will get via the Get Code menu in facebook app dashboard (where you set up your Action, Object and Custom Story)
let properties: [NSObject : AnyObject] = ["og:type": "xxxx:quote", "og:title": "xxxx", "og:description": "Thank you ds sds dsd sd d ds لت"]
//Create the Open Graph object
let object: FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: properties)
//Create the action itself
let action: FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
//This comes from the same Get Code menu, but when you select to get the code for the action
action.actionType = "xxxx:share"
action.setObject(object, forKey: "xxxx:quote")
//Set the image as an Array, as here you can actually post more than one image
action.setArray([ph], forKey: "image")
//Create the content and add the action to it
let content: FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "xxxx:quote"
//Execute the Share Dialog
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)
When I am trying to publish I am getting following error
Error Domain=com.facebook.Facebook.platform Code=102 "(null)" UserInfo={error_reason=The operation couldn’t be completed. (FBAPIErrorDomain error 2500.), error_description=An error occurred during publishing., app_id=3313803xxxxxxx, error_code=102}
I tried to submit app for review on facebook they said following
Your app is using the Share plugin to share content to Facebook, so you don't need to submit for review. Publish_actions is only for posting through the Graph API. See our sharing docs for more info on plugins.
Please help how I can accomplish the requirements of posting Image and Text

How to implement iOS app link Facebook functionality in swift 3?

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...

Using Branch.io generated link with Facebook share dialog

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

Facebook SDK share on iOS not working

I am working on sharing a content on Facebook for an iOS app using Swift.
I have written a singleton class called FBManager and a function as below.
func shareContent(content:String, contentURL:String?, contentTitle:String? , fromController controller:UIViewController {
let shareDialog = FBSDKShareDialog()
let shareLinkContent = FBSDKShareLinkContent()
shareLinkContent.contentDescription = content
if let url = contentURL
{
shareLinkContent.contentURL = NSURL(string: url)
}
if let title = contentTitle
{
shareLinkContent.contentTitle = title
}
shareDialog.delegate = self
shareDialog.fromViewController = controller
shareDialog.shareContent = shareLinkContent
shareDialog.show()
}
But this does not even show a share dialog both on iOS 8 and iOS 9.
Instead the following delegate method gets called
func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) {
}
with the error - "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)"
Can someone please help ?
Facebook SDK's error codes are somewhat ambiguous because they cover rather large domains of errors. The code you provided does not really show the content of the variables and so I cannot pinpoint the problem. However, com.facebook.sdk.share error 2 is an Invalid Argument error, which usually arises from an invalid format of one or more members of FBSDKShareLinkContent.
Generally, you can use the FBSDKErrorCode enum to switch over the (error as NSError).code and find which domain it belongs to. (In this case, it'll point to Invalid Argument)
You can also print(error) directly in the didFailWithError delegate method, which will output a very descriptive log of the error and what caused it specifically.
Check your contentURL, make sure it starts with http:// or https:// or any other valid protocol. Same for the imageURL if you're using or planning to use one. This most likely caused your error!
The SDK's error codes reference may be helpful too.

iOS Twitter URL Scheme which will pre-populate media in a tweet

Is there a URL Scheme by which one can open the twitter app with a given piece of media pre-selected to post along with a pre-selected message?
I know that the following exists:
twitter://post?message=hello%20world
and you can also designate an account:
twitter://post?message=hello%20world&account=helloworld
I would like to be able to open twitter with a pre-selected image or video in the users camera roll along with a message.
Copying my answer from this question
This sorta thing used to be done using Twitter Kit However, Twitter dropped support for TwitterKit.
On October 31, 2018, we will no longer actively contribute to, or accept issues and pull requests on, the open sourced SDKs (iOS, Android, Unity) on GitHub. After this date we will also stop releasing the SDKs through Cocoapods, Carthage, and Bintray JCenter. Documentation and source code for all three SDKs on GitHub will remain available for consumption in an archived state.
Additionally, the use of Twitter kit requires that you have a Twitter application and that the user grants your Twitter application access to their account information.
I was able to solve this problem using Branch.io deep-links.
TLDR
Add branch SDK to your project.
Create a branch url with the url to the image you want to share and any other additional information.
Add "twitter" to your apps info.plist LSApplicationQueriesSchemes
Share that link to Twitter using the default deep links referenced in this answer. Example: twitter://post?message=\(myBranchUrl)
You can find more information on integrating Branch into your iOS project here
You can also checkout some sample code below:
let buo = BranchUniversalObject.init(canonicalIdentifier: "content/12345")
buo.title = "My Content Title"
buo.contentDescription = "My Content Description"
buo.imageUrl = "https://lorempixel.com/400/400"
buo.publiclyIndex = true
buo.locallyIndex = true
buo.contentMetadata.customMetadata["key1"] = "value1"
let lp: BranchLinkProperties = BranchLinkProperties()
lp.channel = "facebook"
lp.feature = "sharing"
lp.campaign = "content 123 launch"
lp.stage = "new user"
lp.tags = ["one", "two", "three"]
lp.addControlParam("$desktop_url", withValue: "http://example.com/desktop")
lp.addControlParam("$ios_url", withValue: "http://example.com/ios")
lp.addControlParam("$ipad_url", withValue: "http://example.com/ios")
lp.addControlParam("$android_url", withValue: "http://example.com/android")
lp.addControlParam("$match_duration", withValue: "2000")
lp.addControlParam("custom_data", withValue: "yes")
lp.addControlParam("look_at", withValue: "this")
lp.addControlParam("nav_to", withValue: "over here")
lp.addControlParam("random", withValue: UUID.init().uuidString)
buo.getShortUrl(with: lp) { [weak self] (url, error) in
if let err = error {
// Handle Error
}
if let branchUrl = url, let urlScheme = URL(string: "twitter://post?message=\(branchUrl)") {
if UIApplication.shared.canOpenURL(urlScheme) {
UIApplication.shared.open(urlScheme, options: [:], completionHandler: nil)
} else {
// Twitter not installed
}
} else {
// Url Error
}
}
This open the Twitter app and looks like this:

Resources