2013-02-19 126 views
0

我想將大文件視頻文件上傳到Facebook,但無論採取何種方法,結果都始終如一。該過程上傳5-35mb的數據然後超時。這發生在WiFi上。無法將大視頻從iOS應用程序上傳到Facebook

我已經嘗試過Facebook SDK 3.1.1,iOS Social Library(即SLRequest)和AFNetworking。

社交庫和聯網會給超時錯誤,而Facebook SDK僅返回代碼5,操作無法完成,HTML錯誤200,但如果通過工具觀看網絡活動,它具有相同的簽名,即存在在停止之前上傳一定數量的兆字節。

請注意,我可以使用以上三種方法中的任何一種方法上傳較小的視頻而不出現任何問題。

有沒有人遇到這個問題,並找到任何解決方案或原因呢?

p.s.我相信它是一個Facebook的bug,如果有其他人想訂閱它,鼓勵他們去調查它(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); 
    } 
}]; 

回答

0

這在最新的SDK已經解決了。它現在沒有問題。

0

graph.facebook.com似乎只接受小視頻。嘗試張貼到graph-video.facebook.com/me/videos代替

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

很高興SDK 3.13.1檢測到'me/videos'調用並將網址替換爲'graph-video.facebook.com' – SoftDesigner 2014-06-11 15:18:13

相關問題