无法从iOS应用程序将大型视频上载到Facebook

无法从iOS应用程序将大型视频上载到Facebook,ios,facebook,video,upload,afnetworking,Ios,Facebook,Video,Upload,Afnetworking,我正在尝试将大文件视频文件上传到Facebook,但无论采取何种方法,结果总是一样的。该过程上载价值5-35mb的数据,然后超时。这种情况发生在WiFi上 我尝试过Facebook SDK 3.1.1、iOS社交库(即SLRequest)和AFNetworking 社交图书馆和afnetworking给出超时错误,而Facebook SDK只返回代码5,操作无法完成,HTML错误200,但如果我通过仪器观看网络活动,它具有相同的签名,即在暂停前上传一定数量的兆字节 请注意,我可以使用这三种方法中

我正在尝试将大文件视频文件上传到Facebook,但无论采取何种方法,结果总是一样的。该过程上载价值5-35mb的数据,然后超时。这种情况发生在WiFi上

我尝试过Facebook SDK 3.1.1、iOS社交库(即SLRequest)和AFNetworking

社交图书馆和afnetworking给出超时错误,而Facebook SDK只返回代码5,操作无法完成,HTML错误200,但如果我通过仪器观看网络活动,它具有相同的签名,即在暂停前上传一定数量的兆字节

请注意,我可以使用这三种方法中的任何一种上传较小的视频,没有任何问题

是否有人遇到过此问题并找到了解决方案或原因?

[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);
  }
}];
p、 我相信这是Facebook的一个漏洞,如果有人想订阅它,我已经在那里记录了一个问题,以鼓励他们进行调查()

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本机库和AFN网络代码

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

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

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

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

SDK 3.13.1检测到“我/视频”呼叫并将url替换为“graph video.facebook.com”很好