Closed bochuanWorkland closed 5 years ago
Hey @bochuanWorkland! Sorry we haven't got an answer to you yet. I added some code formatting to your comment to help make it easier to read. I'll start looking into your issue and see if I can find out what's going on.
i'm also having this issue. The default endpoint is no longer correct. And it's not really documented how and where to find the new one.
In order to do batch results for the youtube api i have to do this:
$batch = new Google_Http_Batch($client,false,null,"batch/youtube/v3/");
The batch path plus the service path seem to be the same not sure if this is just coincidence;
The default api base path of Google_Client
is https://www.googleapis.com
, so it uses https://www.googleapis.com/batch
as the endpoint.
You could change it by setConfig()
in Google_Client
before create $batch
:
$client->setConfig('base_path', 'https://indexing.googleapis.com');
Or create a batch instance by Google_Service_Indexing
.
$client = new \Google_Client();
$client->setAuthConfig('/var/www/html/privateKey.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
$client->setUseBatch(true);
$service = new \Google_Service_Indexing($client);
$batch = $service->createBatch();
// add request
$postBody = new \Google_Service_Indexing_UrlNotification();
$postBody->setType('URL_UPDATED');
$postBody->setUrl('https://example.com/jobs/' . $jobs[$i]['job_id']);
$batch ->add($service->urlNotifications->publish($postBody));
// ---- add request
$results = $batch->execute(); // it does authorize in execute()
Seems like @millyhung posted a solution to the original problem. Thanks @millyhung ! Let's close this, but @bochuanWorkland feel free to reopen if the solution doesn't work for you.
I also have the same problem. I followed all the documentation provided by google. But I do not get the desired result. I would like to get clearer information about this code @millyhung
I can't find the sample codes or documentations I saw. They may have been redirected to Github.
The original problem Not Found
was caused by the wrong endpoint.
I trace the source codes. Google_Http_Batch::execute() L96 $request->getRequestTarget()
returns path instead of full url.
And at L121, request will be sent to $this->rootUrl . '/' . $this->batchPath
.
What is the $this->rootUrl
? See L61, it determines by the base_path
of Google_Client
, and the default value is https://www.googleapis.com
. (See Google_Client L46 and L100)
But Indexing uses the different endpoint https://indexing.googleapis.com/batch
(documentation).
So we need to change the base_path
of client before creating the instance of Google_Http_Batch
or pass the $rootUrl
to the constructor of Google_Http_Batch
.
I encountered the same problem, when I followed the solution provided by @millyhung , the problem was solved! thanks @millyhung !! (however, the documentation is really lack of these detailed information...)
Based on the Indexing API documentation: Using the Indexing API sending a batch request to the Indexing API, should use the following endpoint: https://indexing.googleapis.com/batch However, accessing this url will show this error: 404. That’s an error. The requested URL /batch was not found on this server. I followed this documentation(https://developers.google.com/api-client-library/php/guide/batch) and here is my code:
and here is the running result: //======================= result =====================//
//====================== The End of result ==============//
Then I dive into this documentation (https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html). Instead of using Google_Http_Batch Class which comes from Google API Client Libraries, I use GuzzleHttp\Pool Class, and GuzzleHttp\Psr7\Request Class, and I changed the endpoint from www.googleapis.com/batch to www.googleapis.com/batch/indexing/v3. I am currently forming homogeneous batch requests and here is my code:
and here is the running result: // =================== result ======================//
// =================== The End of result ================= //
I am not sure which endpoint I can use in order to send batch indexing requests using PHP(homogeneous batch requests).
Thanks for any help!