Google-api-php-client: JSON-RPC or Global HTTP Batch serving endpoint migration

Created on 30 Jun 2020  路  11Comments  路  Source: googleapis/google-api-php-client

i've received an email which says that one of my api's (Google Calendar API), i was using an old version library of google-api-php-client, now i upgraded my library to the latest version (v2.5.0)
my question is :
is this enough to avoid the shutdown my app? or do i have to do something else
thanks in advance

question

Most helpful comment

@nasari123 Are you seeing any errors? If so, then check to see how you're instantiating your Batch objects.

Buried in the blog post is this bit, in the Java docs:

Please ensure you are creating your BatchRequest (i.e) com.google.api.client.googleapis.batch.BatchRequest instance via your service client.

This also applies to PHP. If you're instantiating the Batch object yourself, like so:

$batch = new Google_Http_Batch;

Then you should change to creating the batch from the Service class:

$service = new Google_Service_Directory($client);
$batch = $service->createBatch(); // this method will create a Google_Http_Batch with the proper service endpoint

Then you can $batch->add() and $batch->execute() just like normal.

Not sure if this is helpful, but it's something I just came across in some old code and had to dig to fix.

All 11 comments

Hi @nasari123
Can you tell us exactly what the email said? Please be sure to remove any sensitive information that's in there, such as your personal information or your project ID.

Does it seem like the email you received is related to the Global HTTP Batch turndown? If so, follow the steps for migrating in the link I provided.

hello @bshaffer , thanks for replaying,
this is the email
Annotation 2020-06-30 212653

and yes it concerns this blog https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html

mayday

@nasari123 Are you seeing any errors? If so, then check to see how you're instantiating your Batch objects.

Buried in the blog post is this bit, in the Java docs:

Please ensure you are creating your BatchRequest (i.e) com.google.api.client.googleapis.batch.BatchRequest instance via your service client.

This also applies to PHP. If you're instantiating the Batch object yourself, like so:

$batch = new Google_Http_Batch;

Then you should change to creating the batch from the Service class:

$service = new Google_Service_Directory($client);
$batch = $service->createBatch(); // this method will create a Google_Http_Batch with the proper service endpoint

Then you can $batch->add() and $batch->execute() just like normal.

Not sure if this is helpful, but it's something I just came across in some old code and had to dig to fix.

I'm running into this issue as well.

@mattlibera Your suggestion is actually how my code is structured yet I'm still receiving errors.

The blog post says to use a different endpoint: www.googleapis.com/batch/compute/v1

However, I'm not exactly sure how to do this. Any guidance would be appreciated.

@stecca21 Hm, not sure. I haven't used the Compute service myself. What's the error you're seeing?

I'm looking at the Compute.php service class and at least to my eyes it seems properly configured for the endpoint you listed:

$this->batchPath = 'batch/compute/v1'; // line 134

So in theory the code below should result in a proper endpoint config for your $batch object:

$service = new Google_Service_Compute($client);
$batch = $service->createBatch();

$batchPath is a public property - can you inspect its value after you instantiate it to verify the correct value?

@mattlibera forgive me...had an old version of the php client running. I've updated to the latest release and no longer have an issue.

@stecca21 no worries. Glad it's working now!

@nasari123 Are you seeing any errors? If so, then check to see how you're instantiating your Batch objects.

Buried in the blog post is this bit, in the Java docs:

Please ensure you are creating your BatchRequest (i.e) com.google.api.client.googleapis.batch.BatchRequest instance via your service client.

This also applies to PHP. If you're instantiating the Batch object yourself, like so:

$batch = new Google_Http_Batch;

Then you should change to creating the batch from the Service class:

$service = new Google_Service_Directory($client);
$batch = $service->createBatch(); // this method will create a Google_Http_Batch with the proper service endpoint

Then you can $batch->add() and $batch->execute() just like normal.

Not sure if this is helpful, but it's something I just came across in some old code and had to dig to fix.

@nasari123 Is Your issue resolved with this solution?

The correct solution is to update to the latest version of google/apiclient-services (currently ^0.140) and change any instances of $batch = new Google_Http_Batch to $batch = $service->createBatch() instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cmcfadden picture cmcfadden  路  5Comments

ysaurabh33 picture ysaurabh33  路  3Comments

AlexandreGerault picture AlexandreGerault  路  5Comments

whatido1 picture whatido1  路  3Comments

armetiz picture armetiz  路  4Comments