通过ios app(Swift和FBSDK4.0.1)将照片分享到Facebook后无法获得结果post id

时间:2015-04-17 09:45:54

标签: ios facebook swift photo facebook-ios-sdk

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

使用技术Swift和FBSDK 4.0.1

我发现FBSDKShare分享照片照片内容() 无法从方法FBSDKSharingDelegate内的didCompleteWithResults中的结果对象中获取任何帖子ID。
Result对象包含空行:

[:]

但是,FBSDKShare的分享链接内容() 可以从结果对象中获取post 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. Facebook 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")
      
       }
      
    3. 感谢您的帮助。

1 个答案:

答案 0 :(得分: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(“代表叫”)

    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。