I'm in the process of setting up API access to Google Products.
So far, I have
Using the PHP API client, I authenticate using the JSON keyfile as follows:
$client = new Google_Client();
$client->setAuthConfigFile('/path/to/key.json');
$service = new Google_Service_ShoppingContent($client);
Yet, API calls such as
$service->products->insert($merchantId, $product, ['dryRun' => true]);
...fail with the following output:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/content/v2/101033890/products?dryRun=true: (401) Login Required' in /path/to/vendor/google/apiclient/src/Google/Http/REST.php:110
Stack trace:
#0 /path/to/vendor/google/apiclient/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request))
#2 /path/to/vendor/google/apiclient/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)
#3 /path/to/vendor/google/apiclient/src/Google/Http/REST.php(46): Google_Task_Runner->run()
#4 /path/to/vendor/google/apiclient/src/Google/Client.php(590): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#5 /path/to/vendor/google/apiclien in /Users/christian/Projects/imusic/vendor/google/apiclient/src/Google/Http/REST.php on line 110
What could I be doing wrong?
Thanks.
$client = new Google_Client();$cred = $client->loadServiceAccountJson('/path/to/google_api.json', ['https://www.googleapis.com/auth/content']);$oauthClient = new Google_Auth_OAuth2($client);$oauthClient->refreshTokenWithAssertion($cred);$client->setAccessToken($oauthClient->getAccessToken());$service = new Google_Service_ShoppingContent($client);
--
You received this message because you are subscribed to a topic in the Google Groups "Google Content API for Shopping" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-content-api-for-shopping/F5-CNNMkhDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-content-api-fo...@googlegroups.com.
To post to this group, send email to google-content-...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-content-api-for-shopping.
For more options, visit https://groups.google.com/d/optout.