My Business
2K members online now
2K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

Error 401 Request does not have valid authentication credentials CURL PHP

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi Good Morning I am trying to access the API with the library curl

 

this is my code 

 

$api_url = "https://mybusiness.googleapis.com/v3/accounts";

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close ($ch);
print_r($contents);exit();

 

I get this error:

 

{ "error": { "code": 401, "message": "The request does not have valid authentication credentials.", "status": "UNAUTHENTICATED" } }

 

 

Can somebody help me?

 

i have my api application and it was activated.. and i have the client id 

 

So all should be work

 

Help please!!!

1 Expert replyverified_user

Re: Error 401 Request does not have valid authentication credentials CURL PHP

Google Employee
# 2
Google Employee

Hi @TSG A,

 

We see that you are using a PHP cURL script to make requests via the Google My Business API without obtaining an OAuth 2.0 access token from the Google Authorization Server. We strongly encourage you to use the client libraries we provide when interacting with Google's OAuth 2.0 endpoints for the security implications of getting the implementation correct.

 

We recommend you install the v1-branch of the Google API Client Library for PHP in tandem with the official PHP client library for performing OAuth 2.0 authentication and authorization and sending requests via the API.

 

You can find code snippets for both using an OAuth 2.0 client ID and persisting the refresh token, and using a service account, respectively with the Google API Client Library for PHP in this thread.

 

In addition, since the PHP client library doesn’t currently support the display of detailed error messages, we suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site to learn how to use the OAuth 2.0 Playground for troubleshooting errors with detailed error messages when sending requests with data via the Google My Business API.

 

Thanks,

The Google My Business API team