0

我使用了 google js api Link1和 youtube v3 api Link2 我想使用 js 来更新我的视频,列出视频的 js 代码:

var requestOptions = {
playlistId: playlistId,
part: 'snippet',
//id: ['uY3InyzU79U','nOoHrAR50f8'],
myRating:'like',
maxResults: 9
};
if (pageToken) {
requestOptions.pageToken = pageToken;
pToken=pageToken;
}
var request = gapi.client.youtube.videos.list(requestOptions);
request.execute(somefunction());

json响应:

[
{
"id": "gapiRpc",
"result": {
 "kind": "youtube#videoListResponse",
 "etag": "\"Wes3wj_Yozi4a9GfHnpc8qG73KI/8qQBat1N6baCDG6C3Eed_XV_sZo\"",
 "pageInfo": {
  "totalResults": 3,
  "resultsPerPage": 9
 },
 "items": [
{
 "id": "nOoHrAR50f8",
 "kind": "youtube#video",
 "etag": "\"Wes3wj_Yozi4a9GfHnpc8qG73KI/f7JZaoHeZG-CDYzXVRw2Q11Lins\"",
 "snippet": {
  "publishedAt": "2013-05-30T05:37:50.000Z",
  "channelId": "UCx0RClYCMhtsOXRlSyRcuRA",
  "title": "Webcam video from May 30, 2013 3:36 PM",
  "description": "",
  "thumbnails": {
   "default": {
    "url": "https://i3.ytimg.com/vi/nOoHrAR50f8/default.jpg"
   },
   "medium": {
    "url": "https://i3.ytimg.com/vi/nOoHrAR50f8/mqdefault.jpg"
   },
   "high": {
    "url": "https://i3.ytimg.com/vi/nOoHrAR50f8/hqdefault.jpg"
   },
   "standard": {
    "url": "https://i3.ytimg.com/vi/nOoHrAR50f8/sddefault.jpg"
   }
  },
  "channelTitle": "foretribe1",
  "tags": [
   "test",
   "webcam"
  ],
  "categoryId": "22"
 }
 }
]
}
}
]

更新视频js代码:

    var requestOptions = {
    part:'snippet',

    id: String(id),
    snippet:{ title: "ok update"}

};
    var request = gapi.client.youtube.videos.update(requestOptions);
    request.execute(nothing());

请求json:</p>

[{"jsonrpc":"2.0",
  "id":"gapiRpc",
  "method":"youtube.videos.update",
  "params": {
  "part":"snippet",
  "id":"nOoHrAR50f8",
  "snippet":{"title":"ok update"}
   },
   "apiVersion":"v3"
}]

可以看到这里的id和list request json一样,但是还是报错:

[
{
"error": {
"code": 500,
"message": "Video not found",
"data": [
 {
 "message": "Video not found"
 }
 ]
 },
 "id": "gapiRpc"
 }
]

我也在Link2上测试,但也得到 500 错误。

4

1 回答 1

0

您需要将更新包装在“资源”属性中:

gapi.client.youtube.videos.update({
  fields: "snippet",
  part: "snippet",
  resource: {
    id: "vid_id",
    snippet: {
      description: "updating vid",
    }
  }
});

记得在片段中设置其他属性(如 categoryId、tags 等);否则,您将收到另一个错误,或者它们将被取消设置。

最好的方法可能是首先使用 gapi.client.youtube.videos.list 检索视频片段并更改片段,然后调用 gapi.client.youtube.videos.update 并在资源属性中传递更改的片段。

于 2014-03-18T01:16:44.137 回答