我有一个包含数百个子域的站点。我需要通过api并将这些cron作业与php语言脚本一起添加到Google搜索控制台中。
您能否看一下下面的代码,让我知道它有什么问题。没有错误消息,但不会将子域添加到正确的帐户。谢谢!
<?php
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . __DIR__ .'"');
}
require_once __DIR__ . '/vendor/autoload.php';
$DEVELOPER_KEY = 'My_key';
$client = new Google_Client();
$client->setApplicationName("MyProjectName");
$client->setDeveloperKey($DEVELOPER_KEY);
$client->setAuthConfig('file.json');
$scopes = array('https://www.googleapis.com/auth/webmasters');
$client->setScopes($scopes);
$url = "http://sub.example.com";
$webmasters = new Google_Service_Webmasters($client);
$webmasters->sites->add($url); // my problem is here
print_r( $webmasters->sites->listSites()); //works fine, gets back sub-domain
?>
我也面临类似的问题。我已经创建了我的Google服务帐户,并使用它来进行API调用。我正在通过Search Console上的API调用提交网站,调用已成功完成,状态为204,但网站未出现在Google Search Console UI中。请求网址在这里https://www.googleapis.com/webmasters/v3/sites/siteUrl