由於先前有在java自幹過一次 mutipart/form(四年前了@@) ,
這次改用objective c,順道記錄一下。
Youtube Upload API
函式庫
NSURLSessionConfiguration : 做授權
NSMutableURLRequest : 做連線
NSURLSessionUploadTask : 上傳的任務
基本上參考這篇就會寫了
NSURLSessionUploadTask(上传任务)
流程參考
這裡要注意request body跟上傳的endpoint 是比較不一樣的,多了upload XD
13 |
Updated version: Now with custom upload url and sending of metadata with the upload process. The entire process requires 2 requests:
|
設定影片的snippet.title踩雷
最後做一個如下圖的模擬才正確設定影片的title一樣模擬一樣text field的欄任,然後資料就送json string。試了很多種終於成功~XD
回傳結果
重覆的影片內容還會被偵測到XD
{
"kind": "youtube#video",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/UXTZ1WX2E5Fa0kYSvpyTeyKT9LQ\"",
"id": "你的影片id",
"snippet": {
"publishedAt": "2017-02-16T08:54:52.000Z",
"channelId": "UC3b43KuPKlmMa0-s7mlPh9g",
"title": "youtube upload video @ 2017-02-16T16:54:51+08:00",
"description": "youtube upload video @ 2017-02-16T16:54:51+08:00",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/bddGhj46KqY/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/bddGhj46KqY/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/bddGhj46KqY/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "蔡大痣",
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "youtube upload video @ 2017-02-16T16:54:51+08:00",
"description": "youtube upload video @ 2017-02-16T16:54:51+08:00"
}
},
"status": {
"uploadStatus": "uploaded",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}
}
參考
http://www.jianshu.com/p/c50e9fcd6600http://hayageek.com/ios-nsurlsession-example/
http://blog.csdn.net/hello_hwc/article/details/44833683
http://pimacun.github.io/foundation/life-cycle-of-a-url-session
http://ecowork-blog.logdown.com/posts/160123-ios-7-nsurlsession
沒有留言:
張貼留言
留個話吧:)