2015-10-21 55 views
1

我想上傳視頻。我救了我的視頻文件的MP4文件,如下所示:通過video-graph.facebook上傳視頻到Facebook iOS

NSString *fileName = [NSString stringWithFormat:@"chatVideo-%d.mp4",arc4random()%1000]; 
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:fileName]; 
NSURL *videoURL = [NSURL fileURLWithPath:myPathDocs]; 
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset2 presetName:AVAssetExportPresetHighestQuality]; 
exportSession.outputURL = videoURL; 
exportSession.outputFileType = AVFileTypeMPEG4; 
NSData *videodata =[NSData dataWithContentsOfURL:videoURL]; 

我所說的圖形API,用於上傳到Facebook:

[parameters setValue:videoData forKey:@"source"]; 

    [parameters setValue:thumbData forKey:@"thumb"]; 

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/videos" 
             parameters:parameters 
             HTTPMethod:@"POST"] 
    startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
     if ([error.userInfo[FBSDKGraphRequestErrorGraphErrorCode] isEqual:@200]) { 
      NSLog(@"permission error"); 
     } 
    }]; 

但我收到此錯誤:

Sorry, the video file you selected is in a format that we don't support.

回答

4

是的,很長一段時間後,我有找出答案:

[parameters setValue:videoData forKey:@"source"]; 

它必須是:

[parameters setValue:videoData forKey:@"video.mp4"]; 

我討厭Facebook文檔== !.

+0

跆拳道...我有同樣的問題,是試圖做手動形式multipart/form編碼,什麼不...最後,它只是用'video.mp4'來改變'source'。你在哪裏找到這個,如果你還記得的話?(好奇心) –

+1

@MartínMarconcini我參考這個來源:https://github.com/lucascorrea/SCFhotos –

+0

謝謝,Facebook文檔的目標是非常完整,但它已被不同的人/團隊明確寫入,有時是一團糟 –

1

看看

看到支持的視頻類型的列表:

3g2, 3gp, 3gpp, asf, avi, dat, divx, dv, f4v, flv, m2ts, m4v, mkv, mod, mov, mp4, mpe, mpeg, mpeg4, mpg, mts, nsv, ogm, ogv, qt, tod, ts, vob, wmv

人機工程學,檢查視頻是真的一個 MP4視頻......

+0

你可以在上面的代碼中看到,我的名字文件是MP4,輸出也是AVFileTypeMPEG4。 :( –

+0

請確保您將它提交給'graph-video.facebook.com',並且請求被編碼爲'multipart/form-data' – Tobi

+0

我遵循本指南從Facebook。 [鏈接](https://開發人員我有檢查它在sdk運行它調用graph-video.facebook.com –