I simply want to do something like:
curl "https://www.googleapis.com/youtube/v3/videos?id=${ID}&part=snippet&key=${KEY}"
With the Go API to figure out the date of an uploaded video. However after pouring over https://godoc.org/google.golang.org/api/youtube/v3 and the reference, I frustratingly can't figure out how to do this basic task.
I can see VideoSnippet in the godoc, but I don't know how to discover what call returns that.
Use /youtube/v3/videos
(to search) with query parameter part=snippet
. Each returned item will contain a snippet
object with the publish date.
{
"kind": "youtube#videoListResponse",
"etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/Eemxf1NUP9tlqRv5dvxAjeicTjI\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [{
"kind": "youtube#video",
"etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/tq9JVgQy7-68z3ESgWpT0bHx5BE\"",
"id": "9bZkp7q19f0",
"snippet": {
"publishedAt": "2012-07-15T07:46:32.000Z",
...
Example with curl + jq ❤:
$ curl "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=9bZkp7q19f0&key=$KEY" -s | jq -r '.items[0].snippet.publishedAt'
2012-07-15T07:46:32.000Z
[Disclaimer: I myself am not a golang programmer -- only trying to be of help]
According to the docs, publishedAt is at response.Items[].snippet.publishedAt
.
Then you could use as spring of inspiration the Golang code at Search endpoint's examples. Or better the sample code on Github w.r.t. PlaylistItems endpoint.
Also please note that the API does not publish a video's upload date and time. This is private information of the owner of the respective video.
publishedAt (datetime)
The date and time that the video was published. Note that this time might be different than the time that the video was uploaded. For example, if a video is uploaded as a private video and then made public at a later time, this property will specify the time that the video was made public.