我正在尝试通过我正在制作的应用程序在 Facebook 上分享图片。
如果用户在他的 iPhone 上安装了该应用程序,我希望他使用该应用程序而不是 Web 浏览器打开图片链接。我为此目的使用应用程序链接(http://applinks.org/documentation/)
一切正常。但是如果用户没有安装应用程序,他就无法用浏览器打开链接。我认为错误来自我的 webParam(见下文)。
有任何想法吗 ?
var iosParam = "[{\"url\" : \"\(urlScheme)\",\"app_name\" : \"AppName\"}]"
var webParam = "{\"url\" : \"https://www.facebook.com/myAppName\"}"
var param = [
"name" : "app link host",
"ios" : iosParam,
"web": webParam,
"access_token" : token
]
var fbRequest = FBSDKGraphRequest(graphPath: "/app/app_link_hosts", parameters: parameters, HTTPMethod: "POST")
fbRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if error == nil{
let id:String = result["id"] as! String
let token:String = parameters["access_token"]! as! String
var param:[String: String] = ["access_token": token]
// get the canonical URL from the app link host ID
var requestCanonicalURL = FBSDKGraphRequest(graphPath: "/\(id)", parameters: param, HTTPMethod: "GET")
requestCanonicalURL.startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if error == nil {
self.share(result["canonical_url"] as! String)
}else{
NSLog("Error: %@", error)
}
})
}else{
NSLog("Error: %@", error)
}
}
下面是 share() 函数的一些代码:
var properties = [
"og:type": "appType:appType",
"og:title": "What do you think?",
"og:description": "This is a description",
"og:url": canonicalURL,
"og:image": [photo]
]
var object = FBSDKShareOpenGraphObject(properties: properties as [NSObject : AnyObject])
var action = FBSDKShareOpenGraphAction()
action.actionType = "appType:share"
action.setObject(object, forKey: "appObject:appObject")
var content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "previewPropertyName:previewPropertyName"
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)