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.