Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How do I post videos to Facebook?

woxtu
January 13, 2016

How do I post videos to Facebook?

woxtu

January 13, 2016
Tweet

More Decks by woxtu

Other Decks in Technology

Transcript

  1. Prepare to post • Download SDK • Add Frameworks to

    your project • Edit Info.plist • Edit AppDelegate
  2. Post videos let videoUrl = ... let video = FBSDKShareVideo(videoURL:

    videoUrl) let content = FBSDKShareVideoContent() content.video = video FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)
  3. 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) }
  4. How to check app installed? let url = NSURL(string: "fb://")!

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

    { ... } else { FBSDKLoginManager() .logInWithPublishPermissions(["publish_actions"], fromViewController: self) { _ in ... } }
  6. How to get asset URL? extension ViewController: UIImagePickerControllerDelegate { func

    imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let assetUrl = info[UIImagePickerControllerReferenceURL] as? NSURL { ... } } }
  7. 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) ... }
  8. Check list • Your Info.plist • Your AppDelegate • User

    signed in Facebook * Facebook App is installed * Video URL must be asset URL