[英]upload video to facebook using facebook sdk 3.1 on ios 6.0
[英]How to upload video on facebook using facebook sdk 4.6 on iOS8
如何在iOS8上使用facebook sdk 4.6在facebook上上傳視頻。這是我使用的代碼:
FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params tokenString:token.tokenString version:@"nil" HTTPMethod:@"POST" ];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(error)
NSLog(@"%@", error);
else
NSLog(@"Success");
}];
[connection start];
任何幫助表示贊賞。
試試這個代碼。 這個對我有用。
NSDictionary * dictPrivacy = [NSDictionary dictionaryWithObjectsAndKeys:@“ FRIENDS_OF_FRIENDS”,@“ value”,nil]; SBJSON * jsonWriter = [SBJSON新]; NSString * strPrivacy = [jsonWriter stringWithObject:dictPrivacy];
NSString *Url = [[NSBundle mainBundle] pathForResource:@"Video" ofType:@"MOV"]; NSData *videoData = [NSData dataWithContentsOfFile: videoUrl]; //NSData *videoData = [NSData dataWithContentsOfFile:rtfUrl]; NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: videoData, @"video.mov", csString, @"title", strPrivacy,@"privacy", nil]; FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/videos" parameters:params HTTPMethod:@"POST"]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (error) { NSLog(@"fail to upload over Facebook"); } else { NSLog(@"Successfully uploaded over Facebook"); } }];
在Graph APi 2.3+中
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoURL;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video;
[FBSDKShareAPI shareWithContent:content delegate:self];
注意:視頻URL應為Assest URL。
如果不想使用FBSDKShareVideo。
- (void)shareVideoOnFacebook:(NSString*)videoURL{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]){
NSData *videoData = [NSData dataWithContentsOfFile:videoURL];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@" ", @"title",
@" ", @"description",
nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me/videos"
parameters:params
HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error){
if (!error){
NSLog(@"sharing result = %@",result);
}
else{
NSLog(@"error=%@",error.localizedDescription);
}
}];
} else{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
loginManager.loginBehavior = FBSDKLoginBehaviorNative;
[loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error || result.isCancelled) {
NSLog(@"fb error= %@",error.localizedDescription);
}
else{
NSData *videoData = [NSData dataWithContentsOfFile:videoURL];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@" ", @"title",
@" ", @"description",
nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me/videos"
parameters:params
HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error){
if (!error){
NSLog(@"sharing result = %@",result);
}else{
NSLog(@"error=%@",error.localizedDescription);
}
}];
}
}];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.