Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Background • Post videos made with app • Using Facebook SDK for iOS 4.8.0

Slide 3

Slide 3 text

Prepare to post • Download SDK • Add Frameworks to your project • Edit Info.plist • Edit AppDelegate

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Read Quick Start!

Slide 6

Slide 6 text

Required to post videos

Slide 7

Slide 7 text

Required to post videos • NSURL

Slide 8

Slide 8 text

Required to post videos • NSURL • FBSDKShareVideo

Slide 9

Slide 9 text

Required to post videos • NSURL • FBSDKShareVideo • FBSDKShareVideoContent

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Required to post videos • NSURL • FBSDKShareVideo • FBSDKShareVideoContent • FBSDKShareDialog • FBSDKSharingDelegate

Slide 12

Slide 12 text

Post videos let videoUrl = ... let video = FBSDKShareVideo(videoURL: videoUrl) let content = FBSDKShareVideoContent() content.video = video FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)

Slide 13

Slide 13 text

Easy!

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Post it!

Slide 16

Slide 16 text

Nothing happens.

Slide 17

Slide 17 text

an ideal

Slide 18

Slide 18 text

reality

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

The operation couldn’t be completed!

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Read Docs!

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

People who share should have Facebook
 for iOS client installed!

Slide 26

Slide 26 text

Post photos, links, and more Facebook File

Slide 27

Slide 27 text

Post videos Facebook URL File

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

How to check app installed? let url = NSURL(string: "fb://")! if UIApplication.sharedApplication().canOpenURL(url) { ... }

Slide 30

Slide 30 text

How to check user signed in? if FBSDKAccessToken.currentAccessToken() != nil { ... } else { FBSDKLoginManager() .logInWithPublishPermissions(["publish_actions"], fromViewController: self) { _ in ... } }

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

The video URL videoURL must be
 an asset URL!

Slide 33

Slide 33 text

Asset URL?

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

How to get asset URL? extension ViewController: UIImagePickerControllerDelegate { func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let assetUrl = info[UIImagePickerControllerReferenceURL] as? NSURL { ... } } }

Slide 36

Slide 36 text

How to get asset URL? let library = ALAssetsLibrary() library.writeVideoAtPathToSavedPhotosAlbum(videoUrl) { assetURL, error in ... }

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

If you get the error: 
 The operation couldn’t be completed.

Slide 39

Slide 39 text

Check list • Your Info.plist • Your AppDelegate • User signed in Facebook * Facebook App is installed * Video URL must be asset URL

Slide 40

Slide 40 text

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