我正在尝试将视频从iPhone上传到Facebook。我使用FBLoginView登录并创建了一个FBSession。我使用以下代码启动FBRequest上传视频。
- (void)buttonRequestClickHandler:(id)sender {
if (FBSession.activeSession.isOpen) {
[FBSession.activeSession requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceOnlyMe
completionHandler:nil];
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];
NSString *titleString = self.videotitle.text;
NSString *descripString = self.descrp.text;
NSDictionary *videoObject = @{
@"title":titleString,
@"description": descripString,
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);
}];
}
我收到错误 错误:无法完成操作。 (com.facebook.sdk错误5。)
我不确定错误的含义:
我知道我已登录
我不知道我是否正在接通,但我在互联网上使用iPhone
我的参数不正确吗? 我一直在为HOURS弄乱这个没有结果 任何人/每个人的任何帮助将不胜感激。
最后通过进入我的iPhone设置-face并删除我的帐户来完成这项工作。然后,当我点击上传我的应用程序中的视频时,它加载了一个视图,询问Facebook是否可以使用我的应用程序,我说是,然后bam上传。还必须将我的权限更改为只是publish_actions并删除publish_streams,因为这是一个读取权限。无论如何它现在正在运作。接下来让defaultAudience从用户选择的字符串加载而不是硬编码。另一篇文章。
答案 0 :(得分:0)
我猜它与流发布权限有关。试试这种方式。它对我有用。我使用的是Facebook SDK 3.8.0
[self performPublishAction:^{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"faisal" ofType:@"mov"];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *videoObject = @{
@"title": @"This is my title",
@"description": @"This is my description",
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);
}];
}];
和
- (void) performPublishAction:(void (^)(void)) action {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) {
[FBSession.activeSession requestNewPublishPermissions:@[@"publish_stream"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
message:@"Unable to get permission to post"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}
}
答案 1 :(得分:0)
此代码已在 FaceBook SDK 3.14.1
上成功测试建议: .plist文件中的3个属性
设置FacebookAppID,FacebookDisplayName,
网址类型 - >项目0->网址方案设置为facebookappId前缀fb
See
-(void)shareOnFaceBook
{
//sample_video.mov is the name of file
NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:@"sample_video" ofType:@"mov"];
NSLog(@"Path Of Video is %@", filePathOfVideo);
NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
//you can use dataWithContentsOfURL if you have a Url of video file
//NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
//NSLog(@"data is :%@",videoData);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video name ", @"name",
@"description of Video", @"description",
nil];
if (FBSession.activeSession.isOpen)
{
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(@"RESULT: %@", result);
[self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
}
else
{
NSLog(@"ERROR: %@", error.localizedDescription);
[self throwAlertWithTitle:@"Denied" message:@"Try Again"];
}
}];
}
else
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_actions",
nil];
// OPEN Session!
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (error)
{
NSLog(@"Login fail :%@",error);
}
else if (FB_ISSESSIONOPENWITHSTATE(status))
{
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
[self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
NSLog(@"RESULT: %@", result);
}
else
{
[self throwAlertWithTitle:@"Denied" message:@"Try Again"];
NSLog(@"ERROR: %@", error.localizedDescription);
}
}];
}
}];
}
}
我GOT错误:
The operation couldn’t be completed. (com.facebook.sdk error 5.)
当facebook正在进行时就会发生这种情况。下次我打开我的应用程序,它工作正常,它始终是第一次。尝试了应用程序中的所有内容,但似乎是在Facebook SDK端。
看到com.facebook.sdk error 5
的几个原因:
publish_actions
一个旋转。