通过ios应用程序(Swift和FBSDK4.0.1)将照片分享到Facebook后,无法获得结果帖子ID



我正在编写一个iOS应用程序来共享照片。

使用 Swift 和 FBSDK 4.0.1 技术

我发现照片共享由FBSDKSharePhotoContent()无法从方法 didCompleteWithResults 内部FBSDKSharingDelegate的结果对象获取任何帖子 ID 。
结果对象包含空行:

[:]

但是,FBSDKShareLinkContent() 的 URL 共享可以从结果对象中取回帖子 ID。像这样:

[postId: 10000844250000_146108069750000]


我的核心代码的一部分:

  1. 图像选取器控制器 ( UIImagePickerControllerDelegateUINavigationControllerDelegate

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    var theImage:UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    uploadImage.image = theImage
    self.dismissViewControllerAnimated(false, completion: nil)
    }
    


  1. 选择照片后,单击自定义共享按钮

     @IBAction func postButtonClick(sender: AnyObject) {
       let photoContent = FBSDKSharePhotoContent()
       let photo : FBSDKSharePhoto = FBSDKSharePhoto()
       photo.image = uploadImage.image
       photo.userGenerated = true
       photoContent.photos = [photo]
       FBSDKShareDialog.showFromViewController(self, withContent: photoContent, delegate:self)
    }
    
  2. 脸书FBSDKSharingDelegate

     func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject: AnyObject])
     {
        println("sharer didCompleteWithResults, results.count(results.count)")
        println(results)
        // still cannot get post id from photo upload
     }
     func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) {
        println("sharer NSError")
        println(error.description)
     }
     func sharerDidCancel(sharer: FBSDKSharing!) {
        println("sharerDidCancel")
     }
    

我将感谢您的帮助。

    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]!) {
打印("代表已呼叫")

    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")
}

使用上述解决方法,您可以访问 postId。

最新更新