大佬教程收集整理的这篇文章主要介绍了使用iOS6 Social Framework将视频上传到Facebook,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
__block ACAccount * facebookAccount; ACAccountStore* accountStore = [[ACAccountStore alloc] init]; NSDictionary *options = @{ ACFacebookAppIdKey: @"MY APP ID",ACFacebookPermissionsKey: @[@"publish_actions",],@"ACFacebookAudienceKey": ACFacebookAudienceFriends }; ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypEIDentifier:ACAccountTypEIDentifierFacebook]; [accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted,NSError *error) { if (granted) { NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType]; facebookAccount = [accounts lastObject]; NSLog(@"access to facebook account ok %@",facebookAccount.userName); NSData *videoData = [NSData dataWithContentsOfFile:[self videoFileFullPath]]; NSLog(@"video size = %d",[videoData length]); NSDictionary *params = [NSDictionary DictionaryWithObjectsAndKeys: videoData,@"video.mov",@"video/quicktime",@"contentType",@"Video title",@"title",@"Video description",@"description",nil]; NSURL *requestuRL = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"]; SLrequest *request = [SLrequest requestForserviCEType:SLserviCETypeFacebook requestMethod:SLrequestMethodPOST URL:requestuRL parameters:params]; request.account = facebookAccount; [request performrequestWithHandler:^(NSData *data,NShttpURLResponse *response,NSError * error){ NSLog(@"response = %@",responsE); NSLog(@"error = %@",[error localizedDescription]); }]; } else { NSLog(@"access to facebook is not granted"); // extra handling here if necesary } }];
视频数据必须包含在请求的多部分部分中.
现在,需要将参数与多部分数据相关联,这是棘手的部分.因此有必要使用source属性来建立该链接.
source需要一个字符串格式的URL,在参数中设置它,并在multipart请求的filename字段中设置相同的值.
应该这样做.
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"]; NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO]; NSData *videoData = [NSData dataWithContentsOfFile:videoPath]; NSString *status = @"One step closer."; NSDictionary *params = @{@"title":status,@"description":status}; SLrequest *request = [SLrequest requestForserviCEType:SLserviCETypeFacebook requestMethod:SLrequestMethodPOST URL:url parameters:params]; [request addMultipartData:videoData withName:@"source" type:@"video/quicktime" filename:[videoPathURL absoluteString]];
以上是大佬教程为你收集整理的使用iOS6 Social Framework将视频上传到Facebook全部内容,希望文章能够帮你解决使用iOS6 Social Framework将视频上传到Facebook所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。