gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:48:43 25 4
gpt4 key购买 nike

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

使用技术 Swift 和 FBSDK 4.0.1

通过FBSDKSharePhotoContent()发现图片分享无法从方法 didCompleteWithResults 内的 FBSDKSharingDelegate 中的结果对象取回任何帖子 ID。
结果对象包含空行:

[:]

但是,通过FBSDKShareLinkContent()分享的URL可以从结果对象中取回帖子 ID。类似的东西:

[postId: 10000844250000_146108069750000]


我的部分核心代码:

  1. 图像选取器 Controller (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")

    }

我会感谢你的帮助。

最佳答案

    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()

//委托(delegate)方法

func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults 结果: [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。

关于ios - 通过 ios 应用程序将照片分享到 Facebook 后无法获取结果帖子 ID(Swift 和 FBSDK4.0.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29695785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com