YouTube Data API - How to specify the channel you're uploading to? - youtube-api

I am creating an application which will be deployed on various sites and will upload videos from each site to YouTube periodically. I have already got videos uploading but ideally each site would have its own channel.
I had a search to see if anyone has encountered this issue (Don't reinvent the wheel, right?) but the only thing that I found was a couple of threads referencing the onBehalfOfContentOwner parameter detailed in the api here.
This isn't relevant to me as I'm not a content partner; at least I don't think I am. The Google API help documents then sent me here, so here I am.
I have created a YouTube brand account with, for the moment, two channels. Obviously, each one has their own channel id. So far I have tried the following:
Specifying the ChannelId when creating a Video Snippet, I couldn't see anywhere else to set it or an appropriate object to use. I tried with two different channel ids using the same OAuth credentials.
Creating two separate api projects with two unique OAuth credentials and then loading these credentials at runtime. I was only using one set of credentials throughout the lifetime of the app and then changed to the second credential set once I had tested that the upload was still working. The first credential set that I used prompted me to login and
subsequently select an account. The second set didn't prompt me at
all but the video was uploaded on the same account that I had
selected previously. I was logged out of YouTube and my browser was
closed in both instances; the browser does not store any details once it is closed.
I guess really my question is this. What is the best practice for specifying which channel you want to upload to? The application I'm using will be running automatically at set times, so I cannot have user interaction during the upload process. (Selecting an account during initial setup would be fine though!)
Any help is greatly appreciated. Thanks in advance.
EDIT:
I found that the API automatically uses an access token on the local machine if one is present in C:\Users{USERNAME}\AppData\Roaming\Google.Apis.Auth ; even if I am using a different OAuth credential in my application. Deleting the access token file will cause a login prompt to appear the next time you use the api from this machine.
For my application, this will be acceptable as when I deploy there is only the need for a one-time login and gain the access token which will then refresh every hour. It will also mean that I can choose which account/channel I am uploading to for each of our sites. Whilst I acknowledge the answer given by MαπμQμαπkγVπ.0, I do not believe that this is applicable here given that I am not a content partner as previously mentioned.
If someone can tell me how to do this through code instead of deleting the access token, that would of course be a preferred solution. (Or let me know that I am a content partner so I can try the onBehalf parameter)

I found that removing the OAuth token on the PC that my application is running on allows me to reselect the account/channel that I'm uploading to.
It appears that the authorised channel is determined using this token and once present it will automatically refresh every hour. Seeing as one PC will only ever upload to one channel for a given site, I think it is acceptable that I will have to go through a one time setup for each site to gain a token.

When you want to specify the channel you need to upload the video, i think you may need this parameter in your code:
onBehalfOfContentOwnerChannel- This parameter can only be used in a
properly authorized request. This parameter can only be used in a
properly authorized request. Note: This parameter is intended
exclusively for YouTube content partners.
The onBehalfOfContentOwnerChannel parameter specifies the YouTube
channel ID of the channel to which a video is being added. This
parameter is required when a request specifies a value for the
onBehalfOfContentOwner parameter, and it can only be used in conjunction with that parameter. In addition, the request must be
authorized using a CMS account that is linked to the content owner
that the onBehalfOfContentOwner parameter specifies. Finally, the
channel that the onBehalfOfContentOwnerChannel parameter value
specifies must be linked to the content owner that the
onBehalfOfContentOwner parameter specifies.
This parameter is intended for YouTube content partners that own and
manage many different YouTube channels. It allows content owners to
authenticate once and perform actions on behalf of the channel
specified in the parameter value, without having to provide
authentication credentials for each separate channel.

Related

How do I use the YouTube Data API to upload video to secondary channel on personal account

I have looked around Stack Overflow and seen a few posts about this but none of the solutions help.
I have a Google account which I use in YouTube. I have created a second channel on that YouTube account so that I can upload videos with a specific theme to separate them from the main videos.
Trying to use the Google API to upload the videos so that I can run it via a Python script, I keep hitting brick walls with Google who is looking for app verification, privacy policies and web page links - none of which I have.
This application is a Python script that's not available to the public and doesn't gather any public information. All I am trying to do is upload videos to my own personal YouTube account.
So I'm beginning to think it is something else I should be using rather than the API (the uploading web page isn't suitable for use in a script).
My two question are:
Can I use the YouTube API to upload a video directly to the second channel on my personal YouTube account?
Is there another simpler mechanism I should be using to upload videos via a script to my personal YouTube account? The reason I have to do it via script is that the device is unattended.
Thanks,
David
You have to acknowledge that each and every app (this to be understood in a broad sense that includes even a small script like this one from Google upload_video.py) must be verified and approved by Google prior to be able to make videos publicly available via the YouTube site.
Answer to question no. 1: yes, that is perfectly possible.
As part of the OAuth 2.0 authentication/authorization flow, you will be presented, within the browser, with the option of selecting to which account your app is to be given access rights.
You may well exercise this behavior, prior to making use of your script, with the help of Google Developers OAuth 2.0 Playground.
Upon a successful OAuth flow, you may verify (and also revoke) the permissions granted by your account on the account's permissions page.
Answer to question no. 2: no, there's no way to upload programmatically videos on YouTube that's in compliance with YouTube's DTOS, other than using the Videos.insert API endpoint.
Addendum
Since by now you have at least two credentials sets, it may be of need to know to which of your YouTube channels a given credentials object is associated.
If using the Google APIs Client Library for Python, you may easily obtain from the API the channel ID to which a given credentials object CREDENTIALS is associated by issuing a call to the Channels.list API endpoint, passing to it the parameter mine as mine=true:
from googleapiclient.discovery import build
youtube = build(
'youtube', 'v3',
credentials = CREDENTIALS)
response = youtube.channels().list(
mine = 'true',
part = 'id',
fields = 'items(id)',
maxResults = 1
).execute()
channel_id = response['items'][0]['id']
Note that the code above uses the fields request parameter for to obtain from the Channels.list endpoint only the channel's ID info (it is always good to ask from the API only the info that is of actual use).
A caveat using the above procedure is the following: if a given CREDENTIALS instance has its scopes containing only:
https://www.googleapis.com/auth/youtube.upload,
then the API will respond with an error of type insufficientPermissions and of message Request had insufficient authentication scopes.
For to invoke successfully the Channels.list it would be sufficient that the scopes attached to CREDENTIALS to include either of the one below:
https://www.googleapis.com/auth/youtube.readonly,
https://www.googleapis.com/auth/youtube.

YouTube may disable your inactive project's access to the YouTube Data API Service

I was using Youtube Data APIto get youtube video but after getting mail from youtube which says api is disable due to inactive.
Youtube Data api not working since it was disabled by youtube because of inactive for 90 Days. I am not able to call(It is enable in API Console) it even with delete and add new delete back. Please help.
Error shows when i am calling from Web Browsers with api Key i also tried to generate new API key also delete and regenerate new api key but still no luck.
"Access Not Configured. YouTube Data API has not been used in project
264969722993 before or it is disabled. Enable it by visiting
https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=264969722993
then retry. If you enabled this API recently, wait a few minutes for
the action to propagate to our systems and retry."
There are things you can do to try and solve this issue. This first option is to apply for an API exception by filling out this out this form. I've filled out this form and am waiting for a response.
The second option is to create a new project and use that project to generate an API key. Because Google has only disabled access to the Youtube Data API for your current project, the new project's API key should work just fine. I've tried this and can confirm this works. This is probably the more hassle-free option if you have extra projects to spare as Google only allows 10 projects at any point in time.
I'm in the same position, disabled for no calls in 90 days. You can request an exemption but after about 25 back and forth emails it's clear that it is just a smokescreen. After explaining what it's used for they then wanted screenshots, then videos of you using the application, how we use the videos we pull up, and then a shot of the room where it was being used. They even asked who made the video we were looking at (we have no idea!). They want your whole business model and what you do. It was just never ending questions and more stuff to send them. After about 2 1/2 months of slow back and forth, I get a message saying I am out of compliance.
Our application uses YouTube to pull up videos for manufacturers product for research and training in a small training/conference room for internal use only. That's all!
Nothing was out of compliance.
This is the email we received:
Hello ,
We have reviewed your quota extension request for project number
#### and have revoked the allocated quota for your API Client(s) as it is out of compliance on the following YouTube API Services -
Developer Policy:
Policy F. 1 (User Experience - YouTube Look and Feel) Please do not
reply to this email, you may complete and submit this form to re-apply
once the above concern has been addressed.
Thanks, YouTube API Services team
The form link in the email is just a link to start the whole process over again.
According to YouTube policy
If your API Client's quota is reduced or eliminated, you may reapply for quota or a quota extension, and YouTube will review that application based on YouTube’s determination of your expected use of the YouTube API Services.
https://developers.google.com/youtube/terms/developer-policies
I suggest reapplying.
To add to avatarhzh's answer:
If you have already used up your initial cap of max. 12 projects and your channel is a brand account and you do not want to go through the process of applying for more quota/getting back your previous quota, you can also create new projects on a different google account and then add that account to your channel as a manager. It is then possible to access your channel through this new account via the youtube data API.
If your channel is not a brand account yet, you can move your channel to a brand account. This allows you to add different google accounts as managers/co-owners of the channel. Warning: certain things (e.g. comments) cannot be transferred when moving to a brand account.

Search My Own Videos on youtube

I want to allow the visitors of my website to search videos of my youtube account by typing keywords. So far I've been using the "key" parameter to authenticate my other requests and it worked just fine, but for this specific one I am getting a 400 code when setting the myOwnparameter to true.
https://developers.google.com/youtube/v3/docs/search/list#request
If I understand what is said in the documentation by properly authenticated, I'd need to get into the hassle of setting up a OAuth flow just to do that. Beside the inconvenience, this doesn't even seem to address my use case since I don't want the user of my website to be authenticated with his account but with my account : I want the myOwn parameter to point to my account.
How can can I achieve what I am after, with a client-side only solution and - ideally - without OAuth ?
If you want the solution to be client-side only (e.g. a javascript front-end) your authentication credentials should be disclosed to every client and this could be dangerous because anyone could take control of your youtube account.
The solution seems to be to use the channelId parameter and set it to my account.

PHP server-side YouTube V3 OAuth API video upload for different users

Currently I am using a modified script to upload videos. I have taken the following example as a basis:
https://github.com/youtube/api-samples/blob/master/php/resumable_upload.php
This script uses browser based oauth flow.
Could you please tell me if it is possible to allow other users to upload videos to my channel without making them the channel managers? So that they could use my auth token.
If yes - how can it be inplemented?
Yes, that is definitely possible. You need to design an application that is capable of the following:
Authenticate the channel the videos shall be uploaded to via OAuth. As DalmTo said, you need to save the tokens. Whoever has the tokens has access to the channel.
Since your application has access to the channel by now, it (and therefore you) can decide what to upload. That means that you are responsible for granting or denying a specific user the right to upload something.
In order to do so, you could again use OAuth or any other method you like (e.g. you can use your backend accounts).
In other words, a user has to identify towards your application. Your application can then decide to take the user's content and upload it to the channel.

How do you set In Video Promotion on a Youtube channel with a CMS account via the API?

I'm trying to set the in video promotion on a channel via the v3 data API as a CMS user.
If I do this as the channel owner user, then it works fine with the API and testing on the API docs.
However, I am trying to do this via a CMS user. Neither through the site https://developers.google.com/youtube/v3/docs/channels/update nor Python code am I able to do this - I get a 403 back every time.
1) Is what I'm trying to do actually possible? i.e. can a CMS user modify a linked channel, or for updates do I have to be logged in as the channel owner on the API?
2) If 'yes' to point 1, what am I missing to make this work? I have the same working 'body' and 'part' from when I log in as the channel owner, but that just gives me 403's when trying to run it as the CMS user.
I see references to a 'onBehalfOfContentOwner' - is this the secret sauce to make this actually work? And if it is, what should go here? I've tried both the user name and YouTube user id's here for both the CMS user and the channel user, and it seems to make no difference - I still get a 403 every time.
In general, using an OAuth 2 token associated with a CMS user and setting the onBehalfOfContentOwner parameter is the way to make YouTube Data API v3 calls via delegation. What you're attempting does work for many Data API v3 methods, but updating InVideo options is not currently supported via delegation. (The documentation does not make this clear.)
Unfortunately, I don't have any information to share at this time as to whether delegation support will be added to InVideo options at some point in the future.

Resources