我正在关注Google索引API
我想用Google_Service_Indexing发送批量请求。
在PHP中,请帮助我。如何做到这一点。在谷歌文档中,这是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的实例,在第340行的/Applications/MAMP/htdocs/Jukukoushi/src/Controller/ToppagesController.php中调用请求URL:/
我尝试了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);