1

I'm trying to configure the google-api-php-client library in my project. I've already created a custom google app engine project that consists in a cloud endpoint. The project is called 'set-core', the service is called 'vrp API', version 'v1' and the method vrp.vrp.getSolution().

Now in my PHP code i'm following this example: https://developers.google.com/api-client-library/php/start/get_started#building-and-calling-a-service

The problem is that in this example there's no mention how to connect to any custom service, outside Google's ones.

My PHP code is:

$client = new Google_Client();
$client->setApplicationName("set-core");
$client->setDeveloperKey("AIzaSyByd8cRJNGYC4szFLbr3**************");
$client->isAppEngine(true);

$service = new Google_Service_Appengine_Service($client);
$results = $service->vrp->vrp.vrp.getSolution($stringVehicles, $stringServices, $stringDepot);

Unfortunately, on the last line, PHP warns me:

Notice: Trying to get property of non-object (I assume it's $service).

The problem is that I don't really know how to set up all the client's params and which Service type use.

1 Answers1

0

You are going to want to create an authorized HTTP client and then request your API endpoint directly with it. The AppEngine service classes you're manipulating above are not meant for this use case. Something like this should work:

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$httpClient = $client->authorize();
$response = $httpClient->request('GET', 'https://myapp.appspot.com/vrp/getSolution');

The $httpClient class is an instance of GuzzleHttp\Client, but with your Google authentication already added to it. See the documentation for making a request with Guzzle.

I hope this helps!

Brent Shaffer
  • 491
  • 3
  • 11
  • do you know how this could be done with the older v1 library? we are stuck on php5.3 at moment... – jonnie Sep 07 '16 at 13:09