我正在编写一个iOS应用来进行网址共享。
使用技术Swift。
我发现FBSDKShareContent()共享无法从方法didCompleteWithResults内的FBSDKSharingDelegate中的结果对象中获取任何post id。 Result对象包含空行: sharer didCompleteWithResults,results.count0
[:]
插件com.apple.share.Facebook.post无效
这是我的代码
fb分享按钮部分
func showLinkButton()
{
var addURL = "http://tw.yahoo.com"
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string:addURL)
var dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = content
dialog.mode = FBSDKShareDialogMode.ShareSheet
//dialog.delegate = self
dialog.show()
}
2.FBSDKSharingDelegate部分
func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject: AnyObject])
{
println("sharer didCompleteWithResults, results.count\(results.count)")
println(results)
}
func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) {
println("sharer NSError")
println(error.description)
}
func sharerDidCancel(sharer: FBSDKSharing!)
{
println("sharerDidCancel")
}
我的代码出了什么问题?还是有问题? 非常感谢!
答案 0 :(得分:0)
据我所知,post_id
仅在用户登录您的Facebook应用程序并且已授予publish_actions
权限时才会返回。
如果不满足这些条件,则不应返回id。
答案 1 :(得分:0)
let photo = FBSDKSharePhoto()
photo.image = chosenImage
photo.isUserGenerated = false
let photoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
let shareApiInstance = FBSDKShareAPI()
shareApiInstance.message = "customized facebook content"
shareApiInstance.shareContent = photoContent
shareApiInstance.delegate = self
shareApiInstance.share()
//委托方法
func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) {
print("delegates called")
let resultsInfo = results as! [String : Any]
print(resultsInfo["postId"] as! String)
}
func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) {
print("sharer NSError")
print(error.localizedDescription)
}
func sharerDidCancel(_ sharer: FBSDKSharing!) {
print("sharerDidCancel")
}
通过上述解决方法,您可以访问已发布的内容。 如果你有publish_actions权限,那么只有它才有可能