How do I post videos to Facebook?

5e80c846e61904a3de22e6ef728e702e?s=47 woxtu
January 13, 2016

How do I post videos to Facebook?

5e80c846e61904a3de22e6ef728e702e?s=128

woxtu

January 13, 2016
Tweet

Transcript

  1. How do I post videos to Facebook? potatotips #25 @woxtu

  2. Background • Post videos made with app • Using Facebook

    SDK for iOS 4.8.0
  3. Prepare to post • Download SDK • Add Frameworks to

    your project • Edit Info.plist • Edit AppDelegate
  4. None
  5. Read Quick Start!

  6. Required to post videos

  7. Required to post videos • NSURL

  8. Required to post videos • NSURL • FBSDKShareVideo

  9. Required to post videos • NSURL • FBSDKShareVideo • FBSDKShareVideoContent

  10. Required to post videos • NSURL • FBSDKShareVideo • FBSDKShareVideoContent

    • FBSDKShareDialog
  11. Required to post videos • NSURL • FBSDKShareVideo • FBSDKShareVideoContent

    • FBSDKShareDialog • FBSDKSharingDelegate
  12. Post videos let videoUrl = ... let video = FBSDKShareVideo(videoURL:

    videoUrl) let content = FBSDKShareVideoContent() content.video = video FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)
  13. Easy!

  14. Let’s do it @IBAction func post(sender: AnyObject) { let documentsPath

    = "\(NSHomeDirectory())/Documents" let videoUrl = NSURL(fileURLWithPath: "\(documentsPath)/video.mp4") let video = FBSDKShareVideo(videoURL: videoUrl) let content = FBSDKShareVideoContent() content.video = video FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self) }
  15. Post it!

  16. Nothing happens.

  17. an ideal

  18. reality

  19. The operation couldn’t be completed. (com.facebook.sdk.share error 2.)

  20. The operation couldn’t be completed!

  21. None
  22. Read Docs!

  23. None
  24. None
  25. People who share should have Facebook
 for iOS client installed!

  26. Post photos, links, and more Facebook File

  27. Post videos Facebook URL File

  28. None
  29. How to check app installed? let url = NSURL(string: "fb://")!

    if UIApplication.sharedApplication().canOpenURL(url) { ... }
  30. How to check user signed in? if FBSDKAccessToken.currentAccessToken() != nil

    { ... } else { FBSDKLoginManager() .logInWithPublishPermissions(["publish_actions"], fromViewController: self) { _ in ... } }
  31. None
  32. The video URL videoURL must be
 an asset URL!

  33. Asset URL?

  34. File URLs • File URL e.g. file:///private/var/mobile/Containers/Data/Application/ E5F753E8-EF71-4C3F-866B-57C0183984FB/tmp/trim. 5BB698D9-2356-418E-BD15-919129F33D41.MOV •

    Asset URL e.g. assets-library://asset/asset.MOV?id=1C05C4B0- A708-46B6-A665-5AD3020806F3&ext=MOV
  35. How to get asset URL? extension ViewController: UIImagePickerControllerDelegate { func

    imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let assetUrl = info[UIImagePickerControllerReferenceURL] as? NSURL { ... } } }
  36. How to get asset URL? let library = ALAssetsLibrary() library.writeVideoAtPathToSavedPhotosAlbum(videoUrl)

    { assetURL, error in ... }
  37. How to get asset URL? var localIdentifier = "" PHPhotoLibrary.sharedPhotoLibrary().performChanges({

    let request = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(videoUrl)! localIdentifier = request.placeholderForCreatedAsset!.localIdentifier }) { success, error in if success { let ext = videoUrl.pathExtension! let uuid = localIdentifier .substringToIndex(localIdentifier.startIndex.advancedBy(36)) let assetPath = "assets-library://asset/asset.\(ext)?id=\(uuid)&ext=\(ext)" let assetUrl = NSURL(string: assetPath) ... }
  38. If you get the error: 
 The operation couldn’t be

    completed.
  39. Check list • Your Info.plist • Your AppDelegate • User

    signed in Facebook * Facebook App is installed * Video URL must be asset URL
  40. How do I post videos to Facebook? potatotips #25 @woxtu