0

我正在关注 Google 索引API

我想用 Google_Service_Indexing 发送批处理请求。

在PHP中,请帮助我。怎么做。在 Google 文档中,这是 Google_Service_Books。我尝试使用 PHP,例如:

      //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();

我陷入了错误:

传递给 Google_Http_Batch::add() 的参数 1 必须实现接口 Psr\Http\Message\RequestInterface,给出 Google_Service_Indexing_UrlNotification 的实例,在 /Applications/MAMP/htdocs/Jukukoushi/src/Controller/ToppagesController.php 中调用,第 340 行请求 URL: /

4

1 回答 1

1

我尝试使用 PHP 并完成了。

   //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);
于 2018-11-27T10:16:18.137 回答