0

我正在尝试将视频从我的 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 设置-facebook 并删除我的帐户来完成这项工作。然后,当我在我的应用程序中点击上传视频时,它加载了一个视图,询问 Facebook 是否可以使用我的应用程序,我说是的,然后它就上传了。还必须将我的权限更改为仅 publish_actions 并摆脱 publish_streams,因为这是读取权限。无论如何,它现在正在工作。接下来让 defaultAudience 从用户选择的字符串加载,而不是硬编码。另一个帖子。

4

2 回答 2

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();
}
}
于 2013-09-23T11:29:30.130 回答
0

此代码已在Facebook SDK 3.14.1上成功测试

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

设置 FacebookAppID,FacebookDisplayName,
URL types->Item 0->URL Schemes 设置为 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.)

它发生在 facebook 被启动时。下次我打开我的应用程序时,它运行良好,它总是第一次。尝试了应用程序中的所有内容,但它似乎在 Facebook SDK 方面。

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

  • 会话未打开。证实。
  • Facebook 检测到您正在向系统发送垃圾邮件。更改视频名称。
  • Facebook 使用 SDK 有明确的限制。尝试不同的应用程序。
  • 错误的发布权限。旋转publish_actions一下。
于 2014-06-28T14:17:32.820 回答