Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update video on YouTube using API v3

Tags:

youtube-api

I'm trying to use "Try It!" on this page: https://developers.google.com/youtube/v3/docs/videos/update

But I get Bad request error. Where should I set ID of the video I want to update? And what is the request format for updating video title or description?

like image 593
Orange Avatar asked Nov 20 '12 09:11

Orange


People also ask

How do I update my YouTube video?

You can't replace a video because any new video you upload to YouTube will get a new URL. Instead, you can change an existing video: Trim your video: On a computer, you can cut out the beginning, middle, or end of your video. Add cards to your video: You can use cards to add new elements to your video.

Can I upload video to YouTube with API?

The programming language you use does not matter, the quota will be the same. So no there is no other way of uploading videos to YouTube using the api. You should just request a quota extension if you need to upload more videos.

How do I get YouTube data v3 API?

Log in to Google Developers Console. Create a new project. On the new project dashboard, click Explore & Enable APIs. In the library, navigate to YouTube Data API v3 under YouTube APIs.

Is YouTube data API v3 free?

Yes, using the YouTube API does not incur any monetary cost for the entity calling the API. If you go over your quota an 403 Error will be returned by the API.


1 Answers

The request format is to send a "video resource" JSON packet, which looks something like this:

{
"id": "GS9h8M3ep-M",
"kind": "youtube#video",
"etag": "\"MhkxP1IuK4vYJ-nhM3d9E49-2oU/HUmayeWdVX19XyvhE5c2RnbZjgA\"",
"snippet": {
    "publishedAt": "2012-11-10T09:36:49.000Z",
    "channelId": "UC070UP0rK7rShCW1x4B4bgg",
    "title": "Finding Ourselves: The Humanities as a Discipline",
    "description": "Lecture delivered by Geoffrey Harpham, of the National Humanities Center, at the inaugural event of the Brigham Young University Humanities Center.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/hqdefault.jpg"
     }
    },
    "categoryId": "27",
    "tags": [
      "humanities",
      "Harpham",
      "BYU"
    ]
  }
}

When doing an update, you need only send the "id" and "kind" values, along with, in this case, a partial "snippet." Be aware, however, that for writeable attributes -- snippet.title, snippet.description, snippet.tags, snippet.categoryId, and status.privacyStatus -- omitting them will have them revert to the default ('public' for privacyStatus, blank for the other 4). If you were to omit the categoryId, then, it results in a bad request, because it would be as if you were setting it to be in no category, and Youtube doesn't allow a video to not have a category (this is, then, making categoryId a defacto required element). You also have to re-include the tags, the description, and the privacy status (unless you want it to default to public) so they won't be cleared out. Thus to modify the title, you'd include the snippet, its title, and its category ID, like this:

{
 "id": "GS9h8M3ep-M",
 "kind": "youtube#video",
 "snippet": {
    "title": "I'm being changed.",
    "categoryId": "27",
    "tags": [
      "humanities",
      "Harpham",
      "BYU"
    ],
    "description": " can be changed, too, but if I'm not to be I still have to be included as I was before. I will be emptied out if omitted."
  }
 }
like image 169
jlmcdonald Avatar answered Dec 31 '22 18:12

jlmcdonald