Following Google's documentation you should be able to use the YouTube Reporting API without user authentication by using a Service Account.
Currently I have a very simple sample that should give me a list of available Jobs, could be empty though. But I get a 403 permission denied.
Request:
$client = new \Google_Client();
$client->setAuthConfig('service-account-key.json');
$client->addScope(Google_Service_YouTubeReporting::YT_ANALYTICS_MONETARY_READONLY);
$client->addScope(Google_Service_YouTubeReporting::YT_ANALYTICS_READONLY);
$youtube_reporting_service = new \Google_Service_YouTubeReporting($client);
$jobs = $youtube_reporting_service->jobs->listJobs();
Response:
Google_Service_Exception
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
I verified that the following APIs were enabled:
YouTube Reporting API
YouTube Data API v3
YouTube Analytics API
Google+ API (Having my doubts on this one if that is really necessary)
The thing I don't understand is how the relation should be between projects in Google Cloud Platform and the YouTube accounts.
Has this to do with Delegating domain-wide authority to the service account?
Are you then required to have G Suite enabled?
I see a similar question How to grant access to Youtube Reporting API for a google service account?
exists, but that one may be a bit aged since the last response. I hope my samples and additions will shine a new light over this question.
Is there someone with a working sample? May be in other languages. As long as the flow is clear.
In general, service accounts can be used to impersonate a user account. Making authorized calls is mentioned in Preparing to make an authorized API call.
But to answer the question, Service Accounts do not work with the YouTube API:
Service accounts do not work for YouTube Data API calls because
service accounts require an associated YouTube channel, and you cannot
associate new or existing channels with service accounts. If you use a
service account to call the YouTube Data API, the API server returns
an error with the error type set to unauthorized and the reason set to
youtubeSignupRequired.
Related
When i am trying to login in linkedin via php sdk, I am getting this kind of response.
it was not possible to access the API call: it was returned an unexpected > > response status 410 Response: { "errorCode": 0, "message": "This resource is > no longer available under v1 APIs", "requestId": "SGLV7JGIW9", "status": >410, "timestamp": 1556696042967 }
I need to login into own system via linkedin. Thank you.
From you error message:
This resource is no longer available under v1 APIs
... which implies you are using the v1 API of linkedin
Mircrosoft/linkedin has long communicated, at least on its blog and API migration FAQ that v1 API would be deprecated today (1st of May 2019) and that all developers were required to migrate their app to v2.
You will need to use the v2 oAuth platform for Linkedin as v1 is no longer available (We are doing the same) the Microsfot documentation isn't the best however for the API
When I make a call to any v2 LinkedIn share API endpoint such as https://api.linkedin.com/v2/socialActions/{share URN}?oauth2_access_token={access token} I get a response saying "Not enough permissions to access /socialActions/{target} GET ".
Our application was recently given access to marketing API which is how I got the r_ad_campaigns permission. The share API documentation gives no explanation of why this error would occur or what permissions I may be missing. Has anyone been able to successfully make a request to this endpoint or a similar /shares endpoint?
Though it's not clear from the documentation, LinkedIn API is private. You need to request authorisation from them: https://developer.linkedin.com/partner-programs
I'm having the same problem as a few other people have had here on SO. I can't find a single answer to the problem.
Even though live streaming is clearly enabled and I am streaming live, I get this error from the api.
{
"error": {
"errors": [{
"domain": "youtube.liveBroadcast",
"reason": "liveStreamingNotEnabled",
"message": "The user is not enabled for live streaming.",
"extendedHelp": "https://www.youtube.com/features"
}],
"code": 403,
"message": "The user is not enabled for live streaming."
}
}
This user says that it turned out to be a permissions problem. However, his "answer" does not answer the question. Note that I am trying to use this to access information on my own stream, so I should be able to do it, or grant permission to my app. This question was asking how to access other people's stream data, while I want my own data, therefore not a duplicate. Thanks.
YouTube Streaming API says user is not enabled for live streaming
The YouTube Live Streaming API lets you create, update, and manage live events on YouTube. Using the API, you can schedule events (broadcasts) and associate them with video streams, which represent the actual broadcast content.
There for it would make sense for Google to insist that the authenticating account would have live streaming enabled.
I suggest you check that it is enabled for use with the API. How to enable Live streaming Remember that the YouTube Api authentication is channel based. When the user authenticated they had to pick a channel. Could they have picked one that did not have live streaming enabled. Remember you will only have access to the one channel. If the user has more the one channel you will need to authenticate to each one.
While I do agree it seams strange if all you are going to do is list things that you would need to have live streaming enabled this appears to be the way the API works.
Personally i would like to see a public request that would let yous each for others live streams but again that doesn't appear to work with this api. I have logged this as an issue / feature request. Live Streaming API: live streaming not enabled
I've currently got around 100 sites in Analytics across a few different Google Accounts and one single account has full permissions for every site. If possible I'd like to avoid having to manually add permissions for the Google Service account to each analytics profile.
I'm using the Google Analytics PHP Interface
When attempting to impersonate a user using the $delegate_email argument, I get the following exception:
GAPI: Failed to authenticate user. Error: "{
"error": "unauthorized_client",
"error_description": "Unauthorized client or scope in request."
}
I have read elsewhere about needing to 'Delegate domain-wide authority to the service account' using the Google Apps admin console. However we don't have Google Apps at all. Is there any way around this?
tl;dr
Is there a way to get read only access to Google analytics using a service account and impersonating a user without Google Apps?
I would first encourage you to go through the various Scenarios listed on Google OAuth 2.0 documentation and decide which is best for your application.
Service account require that you add a user to each account you wish to access, but with a web server application the end user simply authorizes your application to read their Google analytics data.
The scope you are looking for is:
https://www.googleapis.com/auth/analytics.readonly
I have a question about Google APIs. My goal is to post status to our Google+ company page from server. So it has to be server-side, completely.
I saw hundreds of pages from Google documentation, but I don't understand it at all.
When I try to execute action "plusDomains.activities.insert" (over API Explorer), I'm getting error:
{
"error": {
"errors": [
{
"domain": "plusDomains",
"reason": "forbiddenScope",
"message": "Access to the Google+ Domains API is not allowed as the user has consented to incompatible scopes. See: https://developers.google.com/+/domains/authentication/."
}
],
"code": 403,
"message": "Access to the Google+ Domains API is not allowed as the user has consented to incompatible scopes. See: https://developers.google.com/+/domains/authentication/."
}
}
What is the reason of this error? And what user I have to use? In developers console I have 3 users and 1 full admin (my G-Apps account). What should I set as client-id and to google credentials object?
Many thanks for any advice.
The API Explorer has a bug where it defaults to scopes that are incompatible with Google+ Domains accounts. Go to the Google account permissions list and revoke access from Google APIs Explorer. Go back to the APIs Explorer and authorize again but uncheck the https://www.googleapis.com/auth/plus.login scope leaving only plus.me and plus.stream.write scopes enabled.