Skip to content

Instantly share code, notes, and snippets.

@SongJiaqiang
Created October 13, 2016 11:28
Show Gist options
  • Save SongJiaqiang/59eac9ceb499fe3d8ecaa5b05d5329b5 to your computer and use it in GitHub Desktop.
Save SongJiaqiang/59eac9ceb499fe3d8ecaa5b05d5329b5 to your computer and use it in GitHub Desktop.
- (void)facebookLogin {
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
[self shareVideoOnFacebook];
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut]; //very important line for login to work
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if(!error) {
[self shareVideoOnFacebook];
}
}];
}
}
- (void) shareVideoOnFacebook {
NSString *videoPath = @"/Documents/.../movie.mov";
NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:3L];
[params setObject:videoData forKey:@"video_filename.MOV"];
[params setObject:@"Title for this post." forKey:@"title"];
[params setObject:@"Description for this post." forKey:@"description"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/videos" parameters:params HTTPMethod:@"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
//video posted
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment