【问题标题】:Unable to upload large videos to Facebook from iOS app无法从 iOS 应用程序将大型视频上传到 Facebook
【发布时间】:2013-02-03 13:27:45
【问题描述】:

我正在尝试将大文件视频文件上传到 Facebook,但无论采用何种方法,结果始终相同。该过程会上传 5-35mb 的数据然后超时。这发生在 WiFi 上。

我已尝试使用 Facebook SDK 3.1.1、iOS 社交库(即 SLRequest)和 AFNetworking。

社交库和 afnetworking 会出现超时错误,而 Facebook SDK 只返回代码 5,无法完成操作,HTML 错误 200,但如果我通过工具观看网络活动,它具有相同的签名,那就是在停止之前上传一定数量的兆字节。

请注意,使用这三种方法中的任何一种,我都可以毫无问题地上传较小的视频。

有没有人遇到过这个问题并找到解决办法或原因?

附言我相信这是一个 Facebook 错误,如果其他人想订阅它以鼓励他们调查它,我已经在那里记录了一个问题 (https://developers.facebook.com/bugs/265409976924087)。

Facebook SDK 代码

NSData *videoData = [NSData dataWithContentsOfFile:videoUrlStr options:NSDataReadingMappedAlways error:&lError];
NSString *description = self.streamToShare.videoDescription;

    if (description == nil){
        description = @"";
    }
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:videoData, self.streamToShare.publishedStoryFileName,
                                       @"video/quicktime", @"contentType",
                                       self.streamToShare.name, @"title",
                                       description,@"description",
                                       nil];
[FBRequestConnection startWithGraphPath:@"me/videos" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            if (error) {
                self.errorMessage = [NSString stringWithFormat:@"error: domain = %@, code = %d, description = %@", error.domain, error.code, error.localizedDescription];
            } 
}

iOS 原生库和 AFNetworking 代码

[accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                              options:@{ACFacebookAppIdKey: appID,ACFacebookPermissionsKey: @[@"publish_stream"],ACFacebookAudienceKey:ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
  if(granted){
    NSArray *accounts = [accountStore accountsWithAccountType:facebookTypeAccount];
    facebookAccount = [accounts lastObject];
    NSLog(@"Facebook Login Success");
    NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];
    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:self.streamToShare.publishedStoryURL isDirectory:NO];
    NSDictionary *params = @{
      @"title": self.streamToShare.name,
      @"description": description
    };
    SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:videourl parameters:params];
    [uploadRequest addMultipartData:videoData withName:@"source" type:@"video/quicktime" filename:[pathURL absoluteString]];
    uploadRequest.account = facebookAccount;
    NSURLRequest *urlRequest = [uploadRequest preparedURLRequest];
    NSMutableURLRequest *mutableUrlRequest = [urlRequest mutableCopy];
    [mutableUrlRequest setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
    [mutableUrlRequest setTimeoutInterval:60]; // adjusting this does not fix the issue

    // AF Networking Code                                                
    NSInputStream *stream = [[NSInputStream alloc] initWithData:videoData];
    [mutableUrlRequest setHTTPBodyStream:stream];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:mutableUrlRequest];
    [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
       NSLog(@"%lld bytes out of %lld sent", totalBytesWritten, totalBytesExpectedToWrite, progress);
     }];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSLog(@"Facebook upload success");
      }   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Facebook upload error %@",error.localizedDescription);
      }
     }];
     [operation start];

     // iOS Native Library Upload - Commented out so AFNetworking could be tested                                               
     //NSURLResponse *urlResponse = nil;
     //NSError *urlRequestError = nil;
     /*[NSURLConnection sendSynchronousRequest:mutableUrlRequest returningResponse:&urlResponse error:&urlRequestError];
    if (urlResponse == nil) {
      // Check for problems
      if (urlRequestError != nil) {
         NSLog(@"Error %@", urlRequestError.localizedDescription);
      }
     }
     else {
       // Data was received.. continue processing
       NSLog(@"Worked!");
     }*/


  }else{
    // ouch
    NSLog(@"Permission not granted. Error: %@", error);
  }
}];

【问题讨论】:

    标签: ios facebook video upload afnetworking


    【解决方案1】:

    graph.facebook.com 似乎只接受小视频。尝试改为发布到 graph-video.facebook.com/me/videos

    NSURL *videourl = [NSURL URLWithString:@"https://graph-video.facebook.com/me/videos"];
    

    【讨论】:

    • SDK 3.13.1 检测到 'me/videos' 调用并将 url 替换为 'graph-video.facebook.com' 很好
    【解决方案2】:

    这已在最新的 SDK 中得到解决。它现在可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      相关资源
      最近更新 更多