第一種:看起來有兩種方式可以通過GraphRequest將視頻上傳到Facebook。一個使用「file_url」參數。您提供一個URL和Facebook從外部服務器下載視頻文件。這很像這樣:用iOS上傳到Facebook時編碼視頻的正確方法FBSDK v4(multipart/form-data)
let params = [
"title": "...",
"description": "...",
"file_url": "http://example.com/videofile.mp4"
]
let rq = FBSDKGraphRequest(graphPath: "me/videos", parameters: params, HTTPMethod: "POST")
rq.startWithCompletionHandler { (conn, result, error) -> Void in
// handle error etc..
}
Facebook從我的服務器加載文件,視頻出現在我的時間線上。
另一種方法是使用「source」參數直接上傳視頻。這應該有點像這樣:
let videoURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("testvideo", ofType: "mp4")!)
let rawData = NSData(contentsOfURL: videoURL)!
let params = [
"title": "...",
"description": "...",
"source": rawData
]
但是這個失敗,出現此錯誤消息:
The video you're trying to upload is in a format that isn't supported. Please try again with a video in a supported format.
考慮看看它看起來像視頻數據在「多/形式將被編碼documentation -數據」。該文件甚至提供了一個鏈接到w3。
但是如何做到這一點對我來說仍然是個謎。我試過很多製作FORMDATA串在它的二進制圖像數據的組合等的:
var s = ""
s += "Content-Type: multipart/form-data; boundary=XXXXXXXXXXXXXXXXXXXX\r\n\r\n"
s += "--XXXXXXXXXXXXXXXXXXXX\r\n"
s += "Content-Type: application/octet-stream\r\n\r\n"
let p = "--XXXXXXXXXXXXXXXXXXXX--"
let data = NSMutableData()
data.appendData(s.asUTF8Data())
data.appendData(rawData)
data.appendData(p.asUTF8Data())
let params = [
"title": "...",
"description": "...",
"source": data
]
和其他組合與
s += "Content-Transfer-Encoding: binary\r\n"
s += "Content-Disposition: file; filename=\"video.mp4\"\r\n"
但沒有成功。我總是得到相同的錯誤信息:
The video you're trying to upload is in a format that isn't supported. Please try again with a video in a supported format.
那麼如何包裝視頻文件的形式數據?
以防萬一: 不幸的是,我無法使用FBSDK v4中已經提供的視頻共享功能。
嘿,你有沒有解決這個問題?我也很難找到解決方案。 – hobosf