AdWords
2.1K members online now
2.1K members online now
For questions related to Google Shopping and Merchant Center. Learn to optimize your Shopping ads
Guide Me
star_border
Reply

API access fails with "401 Login required"

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm in the process of setting up API access to Google Products. 

 

So far, I have

  1. a verified merchant account,
  2. an OAuth2 Client ID for an installed/native application (with client ID 1055046914708-nqsq03isi7tntv68gp7unis5270qups0.apps.googleusercontent.com),
  3. granted my own user administrative access in the Merchant Center, as well as
  4. granted (what I presume to be the Client ID user) 1055046914708-nqsq03isi7tntv68gp7unis5270qups0@developer.gserviceaccount.com administrative access in the Merchant Center.

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. 

1 Expert replyverified_user

Re: API access fails with "401 Login required"

[ Edited ]
Top Contributor
# 2
Top Contributor


generally, a login-required message indicates that either the

tokens/authentication are not being properly handled or, the

user did not properly grant permission to the application.

however, the question should likely be addressed within the
content-api forum -- the content-api forum is currently here:
https://developers.google.com/shopping-content/forum/

Re: API access fails with "401 Login required"

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks, I'll post the question there.