How to insert captions to a Youtube video using the Youtube API v3? - youtube

I'm trying to insert captions for a Youtube video using the Youtube API v3. Please note that I am not using any client library for this, only pure Node.js code.
When I make a request to this endpoint:
HTTP Method: POST
URL: https://youtube.googleapis.com/youtube/v3/captions?part=id,snippet
Content-Type: "application/json"
Request Body:
{
"snippet": {
"language": "en",
"name": "Test",
"videoId": "r6RMj7Y-NwL"
}
}
I get this error The request does not contain the caption track contents. and that's clear because I have not uploaded any file, but how to upload it, it's not said how to do that in the Youtube API documentation https://developers.google.com/youtube/v3/docs/captions/insert
How the request should looks like to insert captions to Youtube video. Please help me.
It would be great if you could show how to do that using Node.js/Curl/Java/PHP without using client library

Related

Get the current liveBroadcast name for my channel's "Stream Now" stream via YouTube Live Streaming API

We're starting to use YouTube's Stream Now feature and noticed that while the feature has a static YouTube URL (ie: YouTube.com/channel-name/live) the broadcast/video ID changes whenever a new stream is ended and a new one is started.
Is there a way via the YouTube API to know the current liveBroadcast/video ID for my channel streaming via the Stream Now feature?
And while we are at this, is there a way that this broadcast name in the Stream Now doesn't change and always the same? This would allow reusing the same embed code for all the steams.
Thanks!
You can retrieve the "Stream Now" Broadcast by setting broadcastType to persistent in your request to liveBroadcast/list.
GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2C%20status%2C%20contentDetails&broadcastStatus=all&broadcastType=persistent&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
But after the end of a "Stream Now" stream, the broadcast is converted into a video, and you have to create a new livestream. It's not documented, but I figured out that you can do this by making a call to liveBroadcast/insert with only "isDefaultBroadcast" parameter, set to true
POST https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2C%20status%2C%20contentDetails&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"snippet": {
"isDefaultBroadcast": true
}
}
I hope I help you, it took me many many time to found this, because of the bad documentation of Youtube Live API...

Insert video into someone else's playlist YouTube API v3 results in 403

So I'm trying to insert a video into someone else's playlist (I'm a collaborator). I can insert the video from youtube.com (website), but doing it via the YouTube API V3 gives a 403.
Response:
{ "error": { "errors": [ {
"domain": "youtube.playlistItem",
"reason": "playlistItemsNotAccessible",
"message": "Forbidden" } ], "code": 403, "message": "Forbidden" } }
For the playlists that I own, the youtube api works fine.
Any clue how I can achieve this?
The error indicates that the request made was not properly authorized to insert the specified playlist item
forbidden (403) playlistItemsNotAccessible The request is not properly authorized to insert the specified playlist item.
You can insert a playlist item in your account since you're using it the account authorized by the API. Since you're trying it on a different account, its resulting with the 403 error. I don't know how its possible in the youtube website, though.

How to pass access token for subscribe in youtube v3 data api

How to pass access token in this url for subscribe
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
Hope, this will help you.
First you need to get an authorization from the user.
How to use the Youtube api for subscriptions and
To find your youtube channel ID
Once you have got the authorization from the user whom you want to subscribe to your list.
Then your request should (used from googleapi site)
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet
{
"snippet": {
"resourceId": {
"channelId": "YOUR CHANNEL ID"
}
}
}
ChannelId of yours whom the user wants to subscribe.
You should choose the program where you want to use the api.
URL occurs as
https://www.content.googleapis.com/youtube/v3/subscriptions?part=snippet&key={Base64 of your authorized code}&alt=json

How like/dislike youtube video ios

How i can like/dislike youtube video from my iOS app? I read the documentation, but i can't understand, how make it.
POST /feeds/api/videos/VIDEO_ID/ratings Host: gdata.youtube.com Content-Type: application/atom+xml Content-Length: CONTENT_LENGTH Authorization: Bearer ACCESS_TOKEN GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom"
xmlns:yt="http://gdata.youtube.com/schemas/2007"> <yt:rating value="like"/> </entry>
You need to use youtube API for rating the video. YouTube currently uses a rating system that lets users indicate whether they like or dislike a video. Here is the link
https://developers.google.com/youtube/2.0/developers_guide_protocol_ratings
You need to make a POST request to
https://www.googleapis.com/youtube/v3/videos/rate
And you need to submit the following parameters:
rating: like or dislike (or 'none' to remove the rating from the video)
id: The ID of the video
Your call should look like this:
https://www.googleapis.com/youtube/v3/videos/rate?rating=like&id=E6UTz_Doic
You need you user to have authorized your application via OAuth 2.0 in order to succesfully make a POST call to YouTube's API
You should use Google's API Client Libraries to make the calls and easily setup the authentication.
Reference: https://developers.google.com/youtube/v3/docs/videos/rate

How to enable monetization for videos uploaded with YouTube Data API v3?

I have a verified partner channel on YouTube, and I'm trying to enable monetization for videos uploaded via the YouTube Data API (v3).
The channel is already enabled for monetization, and I've enabled monetization in Channel Settings → Defaults (although I have a feeling that this page is only for setting the defaults on the standard manual upload page). I've looked in the API reference, but can't find anything related to monetization at all.
Is there some other way to automatically make new videos uploaded by any means monetized, or some way I can enable it in the API?
The link that Tareq supplied is correct, but unfortunately it only shows some python code instead of what is going on using HTTP. Since I wanted to do the same, here is what I have figured out and what works for me. Note again that you need access to the ContentID API (vote for this ticket to get this fixed) which means you need to have access to a owners of an CMS Account. Confusingly there exists a YouTube Partner Program which has nothing to do with being a "YouTube Partner". You need access to a CMS account which is e.g. the case if you are running an multi channel network (MCN). Additionally I get the impression that the documentation is actually quite well hidden because even if I know exactly what I am looking for I always have a hard time to find the documentation pages again.
Anyway: Here is the stuff:
1. Create asset
First you need to create an asset (docs):
POST https://www.googleapis.com/youtube/partner/v1/assets?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"type": "web",
"metadata": {
"title": "some title, typically the same as the video title",
"customId": "optional, but typically the same as the videoId"
}
}
In the response body you'll find:
{
...
"id": "ASSET_ID"
...
}
Save the ASSET_ID for later.
2. Set ownership
Now we tell YouTube that we exclusively own everything connected with the asset to 100% exclusively and worldwide (docs):
PUT https://www.googleapis.com/youtube/partner/v1/assets/ASSET_ID/ownership?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"general": {
"owner": "CONTENT_OWNER_ID",
"ratio": 100,
"type": "exclude"
}
}
Note that this is a PUT request and not a POST!
3. Claim the video with a monetization policy
Now we connect the video, the asset and a policy whith each other (docs)
POST https://www.googleapis.com/youtube/partner/v1/claims?onBehalfOfContentOwner=CONTENT_OWNER_ID
Authorization: Bearer ...
{
"assetId": "ASSET_ID",
"videoId": "VIDEO_ID",
"policy": {
"id": "POLICY_ID"
},
"contentType": "audiovisual"
}
Now your video should will be monetized according to some policy.
What you need to know
In my examples you will of course need to replace the variables I left in there in capital letters:
CONTENT_OWNER_ID: Find out your id using and authenticated call to GET https://www.googleapis.com/youtube/partner/v1/contentOwners?fetchMine=true (docs)
ASSET_ID: It is returned in the responseBody of the create asset call
POLICY_ID: Find out what policies with which ids you have with an authenticated call to GET https://www.googleapis.com/youtube/partner/v1/policies?onBehalfOfContentOwner=CONTENT_OWNER_ID (docs)
For all the request you need to be authenticated with the scope https://www.googleapis.com/auth/youtubepartner
This is just one way and option set of applying monetizations. The API endpoints that I showed have more and different options. Refer to the docs.
See also
Vote for this ticket so that default monetization policies are also applied for videos uploaded through the API.
Vote for this ticket so that we get the ability to specify monetization settings during upload without the need to have access to a CMS account
Seems like currently the Data API doesn't respect channel default settings when uploading new videos, nevertheless you can enable monetization (claim ownership) using the Content ID API. See this example
https://developers.google.com/youtube/partner/upload_claim_sample

Resources