How to get Youtube video views by date range - youtube-api

I am trying to get youtube video views by date range and it is working fine with oAuth. But I am using cron script to collect those data through service account, when I try to execute the script it says:
Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUC88Bq63MDJi9szYPEGfv7YA&start-date=2014-02-01&end-date=2016-06-29&metrics=views:
(400) Invalid query. Query did not conform to the expectations".
Could you please help me anyone to resolve this issue. Thanks in advance.

Using service account is not supported by Youtube Analytics and Reporting API
The service account flow supports server-to-server interactions that do not access user information. However, the YouTube Reporting API and YouTube Analytics API do not support this flow. Since there is no way to link a Service Account to a YouTube account, attempts to authorize requests with this flow will generate an error.
Unfortunately, you need to do OAuth2 to get your report.
Resources you can check for information:
Youtube Analytics API PHP Invalid query. Query did not conform to the expectations
Implement OAuth 2.0 Authorization

Related

Enabling youtube data api

I generated an youtube api key, but when I use it in
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=FH2zbHrRY9A&key={YOUR_API_KEY}
it shows me a warning message like
"Access Not Configured. YouTube Data API has not been used in project 950908475774 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=950908475774 then retry"
I have wrote a simple tutorial for this. See Getting Started
You can follow my tutorial to enable the service.
You need to enable this api service before you use the YouTube DATA API.

how can I add people to my Brand Account over api?

I have the access token of a youtube Brand Account owner. With this token I would like to add other people (as admin) to this account over API.
This operation is possible manually (info : https://support.google.com/youtube/answer/4628007?hl=en), but I didn't see anything about user management on youtube-data api.
is this operation is impossible over API or am I looking at the wrong google API documentation ?
It doesn't look like the YouTube v3 Data API supports this operation :(. The only other APIs are analytics and reporting.
For a complete list of what the Data API can do check out this link:
https://developers.google.com/apis-explorer/#s/youtube/v3/
It's not possible with the current YouTube API. If this operation is manually possible over webpages, you can simply write a program (e.g. nodejs application) to execute the steps needed, automatically.

Read data from Youtube Analytics API without Oauth2

I am currently writing a python script to pull information from YouTube Analytics API for a list of separate YouTube channels. The output would be, for example, count video views for each YouTube channel in last month.
My initial idea was to ask each of the YouTube account owners to create a YouTube Analytics app in their console.cloud.google, create a Project, enable the youTube Analytics API, generate an API key and specify that it is needed for the YouTube Analytics API.
I'm testing with one account and if I try to run the script using the API Key generated with the process described above and authenticating like this:
def get_service():
return build('youtubeAnalytics', 'v2', developerKey=API_KEY)
it fails with a HttpError 401 Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
I am not sure if I have done something wrong in creating the API key, or if instead the YouTube Analytics API requires Oauth2 authentication. If the latter is the case, then I am surprised that google console lets you to go all the way and generate API keys and specify that they are needed for the YouTube Analytics API, only for you to find out that you can't use it.
So my question is: do I have to use Oauth2 for YouTube Analytics API or can I use the API key? I'm trying to read data from "my own" account, so why do I need to manually authorise my own app?
Ok I found out that it is not possible to use YouTube Analytics API without OAuth 2.0 authentication. The Google docs and the Google console are very confusing in my opinion as they respectively allow you to create API keys specific for YouTube Analytics API and describe API keys as a possible way to authenticate (only to tell you after that, that all methods require OAuth2.0).
I'm still unclear on how to setup YouTube Analytics API authentication for a command-line python script that does not require users to give manually consent every time the script runs.
I will open a separate question for that.
Set key parameter. You can read data with api key. It's simple.
http -v 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId={playlistId}&part=id,snippet,contentDetails,status&key={api_key}&max_results=10'

Youtube reporting API HttpError 403 error

On my google account (not a Primary account), I have created OAuth credentials which have access to CMS and it's Channels. Using this credentials I am able to fetch data from YouTube Analytics API, so here no problem.
However, when I am trying access YouTube Reporting API, I am only getting the list of reports of Content Owners Reports with an addition of onBehalfOfContentOwner=cms._id parameter and the CMS ID.
def list_report_types(cms):
reporting = youtube.reporting()
request = reporting.reportTypes().list(onBehalfOfContentOwner=cms._id)
results = youtube.query(request)
return results.get('reportTypes')
report_types = list_report_types(cms)
Can anyone help me to also get the list of reports of Channels also?
So when I try to schedule a channel_basic_a2 report, it gives me below error
HttpError 403 when requesting https://youtubereporting.googleapis.com/v1/jobs?alt=json&onBehalfOfContentOwner=cmsid returned "The caller does not have permission">
Thanks in advance.
Two possible issues:
Are the oauth credentials you are using service account credentials? Service accounts do not work for the Youtube Reporting API. See this answer.
Also, have you checked your scopes definition?

Use google calendar with Symfony

I want to access to the calendar to read/create event from the user if he agrees.
I've followed the guide https://developers.google.com/google-apps/calendar/v3/sync
I've actived the api with my google account. Then use the OAuth 2.0 to get a code and the token.
When I follow the test, I use another account to simulate a random user.
Arrived at the lecture of the agenda, I get this error:
Error calling GET https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true&timeMin=2016-06-14T11%3A28%3A25%2B02%3A00: (403) Access Not Configured. Calendar API has not been used in project 1056... before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar/overview?project=1056... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
It seems legit but I don't want the user to active the api on his side...
What am I missing?
Go to Google Developers console and enable the Google Calendar API. You need to tell Google which APIs your application will be accessing.

Resources