iphone sdk在facebook上上传视频

iphone sdk在facebook上上传视频,iphone,objective-c,facebook,facebook-graph-api,Iphone,Objective C,Facebook,Facebook Graph Api,我正在尝试使用FBConnect从iPhone应用程序上传视频。事实上,我试过几种方法,但不幸的是没有成功 首先。使用此处描述的“facebook.video.upload”休息方法和技巧。结果,服务器返回一个空响应,之后还会发生更多的事情。视频不会出现在facebook上。顺便说一句,我已经尝试过不同类型的facebook应用,比如WebApp和Native one 秒。使用“我/视频”图形方法和下面的代码启动上传 > andParams:params和HttpMethod:@“POST” 和

我正在尝试使用FBConnect从iPhone应用程序上传视频。事实上,我试过几种方法,但不幸的是没有成功

首先。使用此处描述的“facebook.video.upload”休息方法和技巧。结果,服务器返回一个空响应,之后还会发生更多的事情。视频不会出现在facebook上。顺便说一句,我已经尝试过不同类型的facebook应用,比如WebApp和Native one

秒。使用“我/视频”图形方法和下面的代码启动上传

>

andParams:params和HttpMethod:@“POST” 和代表:自我]

在这种情况下,我会得到下一个错误:

a) 必须使用活动访问令牌来查询有关 当前用户

b) 视频文件格式不正确 支持

第三。只需发送一封附有视频文件的电子邮件即可video@facebook.com. 不起作用。然而,这个解决方案并不像以前那样感兴趣

我已经花了两天的时间弄清楚这些事情,这让我发疯。请有人分享一个视频上传的工作示例,或者至少指出我在我的示例中的错误


谢谢大家!

您应该使用Graph方法,因为旧的API已被弃用,并将在不久的将来消失。因此,我将解决这个问题

第一个问题是,你不能在没有登录的情况下将视频上传到Facebook。您需要按照以下说明获取访问令牌,然后才能上载视频:

您还需要
upload\u video
权限,由于某些原因,“权限”页面上没有列出该权限

我不确定第二个问题,但Facebook支持。你的视频大概是苹果的一种格式,这可能是受支持的。修复第一个问题,看看这对第二个问题是否有影响。

从Facebook官方开发者网站上找到上传视频的简单来源。
NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *urlString=[urlvideo path];

NSLog(@"urlString=%@",urlString);
NSString *str = [NSString stringWithFormat:@"you url of server"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setFile:urlString forKey:@"key foruploadingFile"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusCode %@",[request responseString]);
他们有点老了,但仍然工作得很好。 也许这个消息来源会对某人有所帮助。 但别忘了将AppID更改为您的。我已经在三个地方成功了

facebook=[[facebook alloc]initWithAppId:@“…”; 和plist文件中的2个属性-FacebookAppID、URL类型数组


祝你好运

此代码在

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

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

-(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错误5的原因不多:

  • 会话未打开。验证
  • Facebook检测到您正在向系统发送垃圾邮件。更改视频名称
  • Facebook使用SDK有一个已定义的限制。尝试其他应用程序
  • 错误的发布权限。给
    publish\u动作
    一个旋转

尝试此修复:上面的示例需要GCC提供参考。
- (IBAction)buttonClicked:(id)sender {
     NSArray* permissions = [[NSArray alloc] initWithObjects:
                        @"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}

- (void)fbDidLogin {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"buf-3" 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];
[facebook requestWithGraphPath:@"me/videos"
                     andParams:params
                 andHttpMethod:@"POST"
                   andDelegate:self];
}
-(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.)