Leo Ka Ho Lee
Leo Ka Ho Lee

Reputation: 41

Cannot get result post id after sharing photo to Facebook by ios app (Swift and FBSDK4.0.1)

I'm writing an iOS app to do photo sharing.

Using technology Swift and FBSDK 4.0.1

I found that photo sharing by FBSDKSharePhotoContent() CANNOT get back any post id from result object in FBSDKSharingDelegate inside method didCompleteWithResults.
Result object contains empty row:

[:]

However, URL sharing by FBSDKShareLinkContent() can get back post id from the result object. something like that:

[postId: 10000844250000_146108069750000]


Part of my core code:

  1. Image Picker Controller (UIImagePickerControllerDelegate, UINavigationControllerDelegate)

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


  1. After choosing photo, click custom share button

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

I will appreciate your help.

Upvotes: 4

Views: 2078

Answers (1)

Bharath Kumar
Bharath Kumar

Reputation: 1

    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 Methods

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

with the above workaround you can access postId.

Upvotes: 0

Related Questions