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

Unable to connect MyBusiness with google-api-php-client.

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

Hi, m newbie with google API and stuck into a typical situation.
I am building a php based centralized admin area where admin can see all his business locations, reviews, ratings etc.

I am using google-api-php-client and some-how I manage to install it with composer. the login pert went well and i have successfully store user token to DB (for future access).

 

require './google_sdk/vendor/autoload.php';
$client = new Google_Client();
$client->addScope(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/books', 'https://www.googleapis.com/auth/plus.business.manage'));
$client->setAccessType('offline');
$client->setAuthConfigFile('./google_sdk/client_secret.json');
$client->setDeveloperKey(gp_DeveloperKey); /*- defined -*/
if($_SESSION['google_access_token']!=NULL && $_SESSION['google_access_token']!=""){
        $client->setAccessToken($_SESSION['google_access_token']);
        try{
                $activeAct=$_REQUEST['act']!=""?$_REQUEST['act']:'feeds';
               switch($activeAct){
                       case "feeds":
                              include_once("google_feeds.php");
                       break; 
                       case "reports":
                               include_once("google_reports.php");
                       break; 
                       default:
                               echo '<h3 align="center">Error Occured</h3>';
                       break;
               }
        }catch(Exception $e){
               echo "<pre>";
               print_r($e->getMessage());
               echo "</pre>";
               exit(); 
} }else{ $client->setRedirectUri($URL.'social_report.php?tab=gp'); if(isset($_GET['code']) && $_GET['code']!="" ){ $client->authenticate($_GET['code']); $_SESSION['google_access_token'] = $client->getAccessToken(); @mysql_query("UPDATE `user` SET `user_gp_token`='".$_SESSION['google_access_token']."' WHERE `user_id`='".$_SESSION["user_id"]."'; "); ?> <script> window.location="<?=$URL.'social_report.php?tab=gp'?>"; </script> <?php }else{ $auth_url = $client->createAuthUrl(); ?> <div class="row text-center" style="margin:80px 0px;"> <a href="<?=$auth_url?>"> <img src="img/sign-in-google.png" alt="Google Login" /> </a> </div> <?php }


And, it successfully accessing "google_feeds.php".

 

FYI, Above code is working and asking permission for all four Scopes ( 'auth/books' is used for testing ans it is working and returning data). Project ID approved for MyBusiness API access from google end.

 

Now, in google_feeds.php I am trying to call the "Google_Service_Mybusiness", for that purpose i downloaded 'google-api-services-mybusiness-v3-php-rev-20160505-1' from GIT and paste the 'Mybusiness.php' to 'google_sdk/vendor/google/apiclient/src/Google/Service/'.

 

Please check the 'google_feeds.php':

 

 require './google_sdk/vendor/google/apiclient/src/Google/Service/Mybusiness.php';
$Oauth2Service = new Google_Service_Oauth2($client);
$user = $Oauth2Service->userinfo->get();
$gmbService = new Google_Service_Mybusiness($client);
$results = $gmbService->accounts->listAccounts();
echo "<pre>"; print_r($results); echo "</pre>";

 

And it is Catching the error:

Error calling GET https://www.googleapis.com/v3/accounts?key=AIzaSyDo4h3OjOcUImlqC0iPUYOK68ZQmZvGjiE: (404) Not Found

 

I can see above is calling GET on 'https://www.googleapis.com/v3/' instead of 'https://mybusiness.googleapis.com/'. Not sure how to manage it. Please Help.

 

Also, I have tried with 'https://developers.google.com/oauthplayground/' but it also returning error:

{
  "error": {
    "status": "NOT_FOUND",
    "message": "Method not found.",
    "code": 404
  }
}

 

Please let me know what i am missing here. Thank you for your time and patience. :)

ANJAN

3 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Raj S
July 2016

Re: Unable to connect MyBusiness with google-api-php-client.

Google Employee
# 2
Google Employee

Hi @Raj S,

 

I’ve replied to your question privately on a separate thread. If it’s necessary, I’ll follow up with you about your technical question here on this thread.

 

Thanks,

Terry

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Dear Terry,
Sorry, I am unable to locate where that Private Thread Option is. Also I have a mail from "The Google My Business API team" and I submit my reply on the same.

My Gmail account is: admin@yourmarketingdashboard.com if you please prefer to respond through mail or hangout.

Thanks,
Anjan

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Hi Terry,

I've the same problem as Raj, could you help me out?

Re: Unable to connect MyBusiness with google-api-php-client.

Google Employee
# 5
Google Employee

Hi @Martin L,

 

We’ll reach out to you privately on a separate thread.

 

Thanks,

Terry

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
I don't know if your problem is still open but I've worked it out.
It's simple the $rootUrl variable is not passed through because of an old version of the 'google-api-php-client'.
The $rootUrl has to be declared e.g. in your Service.php if that isn't the case your API is to old to work properly with MyBusiness API.

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Terry, I am facing the extract same issue.

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
Dear Martin,
I have already seen that and that is the cause for calling "https://www.googleapis.com/v3/accounts?key=***" instead of 'https://mybusiness.googleapis.com/v3/accounts?key=***' as I stated earlier.
About the 'google-api-php-client', I installed it on 25th May 16 using composer. So I don't think it is a version Issue.

There is one thing that bugging me is there was no "Mybusiness.php" for "Google_Service_Mybusiness" in "vendor\google\apiclient\src\Google\Service" directory. So i just download that "google-api-services-mybusiness-v3-php-rev-20160505-1" and paste it to Service directory. Then i just include it as you can see above in my previous (main) post. Is there is anything I am missing?

Thanks for your time :)

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Another thing is that it also doesnt work on O Auth playground, so it
shouldnt be something with google api clieny

Re: Unable to connect MyBusiness with google-api-php-client.

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭
Dear Zubair
Did you approve your Project to Google yet? If No, please check the link for "Request access to the API" : https://developers.google.com/my-business/content/prereqs and also submit the access request form: https://docs.google.com/forms/d/1XTQc-QEjsE7YrgstyJxbFDnwmhUhBFFvpNJBw3VzuuE/viewform.