1

I'm following Google indexing API

And I want to send batch request with Google_Service_Indexing.

In PHP, please help me. How to do it. In Google document, this is Google_Service_Books. I tried with PHP like :

      //set google client
      $client = new Google_Client();
      $client->setAuthConfig('my_key.json');
      $client->addScope('https://www.googleapis.com/auth/indexing');
      $client->setUseBatch(true);
      //set batch
      $batch = new Google_Http_Batch($client);
      //set service
      $service = new Google_Service_Indexing($client);

      $postBody = new Google_Service_Indexing_UrlNotification();
      $postBody->setType('URL_UPDATED');
      $postBody->setUrl('https://my_job_detail');
      $service->urlNotifications->publish($postBody);
      $batch ->add($service);
      $results = $batch->execute();

And I stuck in error :

Argument 1 passed to Google_Http_Batch::add() must implement interface Psr\Http\Message\RequestInterface, instance of Google_Service_Indexing_UrlNotification given, called in /Applications/MAMP/htdocs/Jukukoushi/src/Controller/ToppagesController.php on line 340 Request URL: /

Rua Tahi
  • 238
  • 5
  • 15
  • 1
    _“I try with PHP like :”_ - and …? Did it work? Do you get errors? What happens? Please go read [ask], and then edit your question accordingly! – misorude Nov 26 '18 at 12:34

1 Answers1

2

I tried with PHP and completed.

   //init google client
    $client = new Google_Client();
    $client->setAuthConfig('your_path_to_key.json');
    $client->addScope('https://www.googleapis.com/auth/indexing');
    $client->setUseBatch(true);

    //init google batch and set root URL
    $batch = new Google_Http_Batch($client,false,'https://indexing.googleapis.com');

    //init service Notification to sent request
    $postBody = new Google_Service_Indexing_UrlNotification();
    $postBody->setType('URL_UPDATED');
    $postBody->setUrl('https://your_job_detail');

    //init service Indexing ( like updateJobPosting )
    $service = new Google_Service_Indexing($client);
    //create request
    //$service->urlNotifications->createRequestUri('https://indexing.googleapis.com/batch');
    $request_kame = $service->urlNotifications->publish($postBody);
    //add request to batch
    $batch ->add($request_kame);
Rua Tahi
  • 238
  • 5
  • 15
  • Hi @rua-tahi I am also working on the google indexing batch request but with nodeJs, I am wondering how this can work when the init google batch does not through [/batch] (https://indexing.googleapis.com/batch) ? Another question is didn't you have to deal with multipart/mixed part to get the batch request done? If that's the case, could you please read my [post](https://stackoverflow.com/questions/54337324/how-to-send-multipart-mixed-request-for-google-indexing-batch-request-in-nodejs) and give me some advice if you see something. Thanks in advance! – Jing Jan 24 '19 at 11:58