将视频上传至Facebook的错误5(uploading video to Facebook err

2019-10-30 09:46发布

我想从我的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互联网上

是我的参数不正确的? 我一直在搞乱这个对于没有结果任何人/每个人任何帮助将不胜感激小时。

最后,通过进入我的iPhone设置,Facebook和删除自己的帐户得到了这个工作。 然后,当我拍了拍上传的视频在我的应用程序加载它是问如果Facebook可以用我的应用程序,我说是的,然后咣当其上传的视图。 也不得不改变我的权限只是publish_actions,摆脱publish_streams的,因为这是一个读取权限。 反正它现在的工作。 接下来让defaultAudience从用户挑选,而不是硬编码字符串加载。 另一篇文章。

Answer 1:

我猜它是与流出版许可。 试试这个方法。 它为我工作。 我使用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();
}
}


Answer 2:

此代码测试成功在Facebook的SDK 3.14.1

建议:在的.plist文件3个属性

设置FacebookAppID,FacebookDisplayName,
URL类型- >项目0-> URL方案设置为facebookappId前缀fb

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

                                                                   }];
                                         }
                                     }];
        }
}

和我的错误:

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

正在inited的Facebook时,它发生。 下一次,我打开我的应用程序,它工作正常,它总是在第一时间。 尝试过的应用程序的一切,但它似乎对Facebook的SDK侧。

几个原因看到com.facebook.sdk error 5

  • 会话是不开放的。 验证。
  • Facebook已经检测到您在垃圾邮件系统。 更改视频名称。
  • Facebook拥有使用SDK定义的限制。 尝试不同的应用程序。
  • 错误的发布许可。 给publish_actions旋转。


文章来源: uploading video to Facebook error 5