简体   繁体   English

iphone sdk 上传视频到 facebook

[英]iphone sdk upload video on facebook

I am trying to upload video from the iPhone application using FBConnect.我正在尝试使用 FBConnect 从 iPhone 应用程序上传视频。 Actually I have tried several ways but unfortunately without any success.其实我已经尝试了几种方法,但不幸的是没有任何成功。

First.第一的。 Using " facebook.video.upload " REST method and tricks described here iPhone Facebook Video Upload .使用“ facebook.video.upload ”REST 方法和技巧在这里描述iPhone Facebook 视频上传 As a result server returns an empty response and anything more happens afterwards.结果服务器返回一个空响应,之后会发生更多事情。 Video doesn't appear on facebook. facebook 上未显示视频。 Have tried different types of facebook apps by the way, such as WebApp and Native one.顺便尝试了不同类型的 facebook 应用程序,例如 WebApp 和 Native 一个。

Second.第二。 Using " me/videos " GRAPH method and below code to initiate uploading使用“我/视频” GRAPH 方法和下面的代码来启动上传

> >

     NSMutableDictionary *params = [NSMutableDictionary
 dictionaryWithObjectsAndKeys:movieData,
 @"source", @"File.mov", @"filename",
 nil];
 [m_facebook requestWithGraphPath:@"me/videos"

andParams:params andHttpMethod:@"POST" andDelegate:self]; andParams:params andHttpMethod:@"POST" andDelegate:self];

In such a case I'm getting the next errors:在这种情况下,我会收到下一个错误:

a) An active access token must be used to query information about the current user. a) 必须使用活动访问令牌来查询有关当前用户的信息。

b) Video file format is not supported. b) 不支持视频文件格式。

Third.第三。 Simply send an email with video file attached to video@facebook.com.只需发送 email 并附上视频文件到 video@facebook.com。 Doesn't work.不工作。 However this solution is not so interested as previous are.然而,这个解决方案不像以前那样感兴趣。

I have spent 2 days figuring those things out and it makes me crazy.我花了 2 天时间弄清楚这些事情,这让我发疯。 Could someone please share a working example of video uploading or at least point me out where I am wrong in my samples.有人可以分享一个视频上传的工作示例,或者至少指出我在样本中的错误所在。

Thank you!谢谢!

You should use the Graph method, since the old API is deprecated and will go away at some point in the fairly near future.您应该使用 Graph 方法,因为旧的 API 已被弃用,并且 go 将在不久的将来某个时候消失。 Therefore, I'll address that.因此,我会解决这个问题。

The first problem is that you can't just upload a video to Facebook without being logged in somehow.第一个问题是您不能在没有登录的情况下将视频上传到 Facebook。 You'll need to follow these instructions to get an access token before you can upload videos: http://developers.facebook.com/docs/authentication您需要按照以下说明获取访问令牌,然后才能上传视频: http://developers.facebook.com/docs/authentication

You'll also need the upload_video permission, which for some reason isn't listed on the "Permissions" page.您还需要upload_video权限,由于某种原因,该权限未在“权限”页面上列出。

I'm not sure about the second issue, but Facebook supports a number of video formats .我不确定第二个问题,但 Facebook 支持多种视频格式 Presumably your video is in one of the Apple formats, which are probably supported.大概您的视频是其中一种可能受支持的 Apple 格式。 Fix the first issue, and see if that has any effect on the second one.修复第一个问题,看看是否对第二个问题有任何影响。

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]);

Found simple sources from official Facebook developers site for uploading videos.从官方 Facebook 开发者网站上找到简单的资源用于上传视频。

They are little old, but still working fine.他们有点老,但仍然工作正常。 http://developers.facebook.com/attachment/VideoUploadTest.zip Maybe this source will help to someone. http://developers.facebook.com/attachment/VideoUploadTest.zip也许这个来源会对某人有所帮助。 But don't forget to change AppID to your.但不要忘记将 AppID 更改为您的。 I've made it in 3 places我在 3 个地方成功了

facebook = [[Facebook alloc] initWithAppId:@"..."]; facebook = [[Facebook alloc] initWithAppId:@"..."]; and 2 properties in plist file - FacebookAppID, URL types array http://i.stack.imgur.com/yZAXQ.png和 plist 文件中的 2 个属性 - FacebookAppID、URL 类型数组http://i.stack.imgur.com/yZAXQ.png

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

Good luck!祝你好运!

This Code is Tested successfully On FaceBook SDK 3.14.1此代码在FaceBook SDK 3.14.1上测试成功

Recommendation: 3 properties in.plist file推荐: .plist文件中的3个属性

set FacebookAppID,FacebookDisplayName,设置 FacebookAppID、FacebookDisplayName、
URL types->Item 0->URL Schemes set to facebookappId prefix with fb See URL types->Item 0-> URL Schemes set to facebookappId prefix with 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);
                                                                       }

                                                                   }];
                                         }
                                     }];
        }
}

And I GOT Error When app Is Run First time:第一次运行应用程序时出现错误:

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

It happens when facebook is being inited.它发生在 facebook 被初始化时。 Next time i open my app, it works fine, its always the first time.下次我打开我的应用程序时,它运行良好,它总是第一次。 Tried everything in app, but it seems to be on the Facebook SDK side.尝试了应用程序中的所有内容,但它似乎在 Facebook SDK 方面。

Few causes for seeing com.facebook.sdk error 5 :看到com.facebook.sdk error 5的几个原因:

  • Session is is not open. Session 未打开。 Validate.证实。
  • Facebook has detected that you're spamming the system. Facebook 检测到您正在向系统发送垃圾邮件。 Change video name.更改视频名称。
  • Facebook has a defined limit using the SDK. Facebook 使用 SDK 具有定义的限制。 Try a different app.尝试不同的应用程序。
  • Wrong publish permission.错误的发布权限。 Give publish_actions a spin.publish_actions一个旋转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM