I'm trying to use the Google analytics API. I created an account in the developer console, I use the OAuth2 to grant access to users data. So I have my refresh_token. But now, I would like to get all profilesID in GA for the account I have access to. I follow the Google's official tutorial and I get this error :
{
"error": {
"errors": [{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}],
"code": 401,
"message": "Login Required"
}
}
I see that i missed the credential but I dont know how to passe the access_token in this call. Here is my code :
$client = new Google_Client();
$client->setApplicationName("APP_NAME");
$client->setAuthConfig(GA_KEYS_JSON);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_Analytics($client);
// Get the list of accounts for the authorized user.
$accounts = $analytics->management_accounts->listManagementAccounts();
$items = $accounts->getItems();
var_dump($items);die();
Any idea ?