我有一个工作门户网站(Wordpress + PHP),我希望我的网站使用谷歌索引API。我对GoogleAPI没有任何经验,所以我只看了他们的指导。根据指南,要使用索引API,它有三个步骤:
我完成了第一步,但是第二步和第三步确实让我感到困惑。似乎我需要通过编码获得OAuth令牌,但是我把这些代码放在哪里呢?对于使用API,他们向我展示了以下示例:
POST https://indexing.googleapis.com/v3/urlNotifications:publish
{
"url": "https://careers.google.com/jobs/google/technical-writer",
"type": "URL_UPDATED"
}
同样,我也不知道该把这些块代码放在哪里去使用API。有人知道这件事,能一步一步地向我解释如何为我做这件事吗?最后一个问题:因为我的网站每天有10-15个新职位。我可以设置这个索引API自动发送请求到谷歌,每当有人发布一个新的工作?致以敬意,
发布于 2020-01-24 16:02:05
激活Google索引API:https://console.developers.google.com/apis/library/indexing.googleapis.com
在PHP中,您可以找到有关错误的更多信息:
$body = $response->getBody();
$stringBody = (string) $body;
发布于 2018-09-05 06:07:14
您应该在请求中将其作为比勒身份验证头传递。
授权:持票人
您也可以将其作为请求字符串传递,但我不记得这是否适用于post调用。
POST https://indexing.googleapis.com/v3/urlNotifications:publish?Access_token=XXXX
{
"url": "https://careers.google.com/jobs/google/technical-writer",
"type": "URL_UPDATED"
}
如果您使用的是php,您应该考虑使用Google客户端库,它将为您处理大部分问题。这是他们在示例这里中推荐的
require_once 'google-api-php-client/vendor/autoload.php';
$client = new Google_Client();
// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig('service_account_file.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
// Get a Guzzle HTTP Client
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
// Define contents here. The structure of the content is described in the next step.
$content = "{
\"url\": \"http://example.com/jobs/42\",
\"type\": \"URL_UPDATED"
}";
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
确保正确设置了服务帐户,创建服务帐户
发布于 2018-11-28 03:17:33
您必须确保在搜索控制台中验证站点所有权:https://www.google.com/webmasters/tools/home
您可以像my-service-account@project-name.google.com.iam.gserviceaccount.com一样确认您的服务帐户
https://stackoverflow.com/questions/52177754
复制相似问题