Google Indexing API [英] Google Indexing API

查看:216
本文介绍了Google Indexing API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个求职门户网站(Wordpress + PHP),我想为我的网站使用Google Indexing API.我没有任何关于GoogleAPI的经验,所以我只是阅读了他们的指导. 根据指南,要使用Indexing API,它需要3个步骤:

I have a job portal website (Wordpress + PHP) and I want using Google Indexing API for my website. I don't have any experience on GoogleAPI so I just read their guidance. According to the guide, to use the Indexing API it has 3 steps:

  1. 通过启用Indexing API,创建新的服务帐户并在Search Console中验证所有权来完成先决条件.
  2. 获取访问令牌以验证您的API调用.
  3. 发送请求以将新的,更新的或删除的网页通知Google.
  1. Complete the prerequisites by enabling the Indexing API, creating a new service account, and verifying ownership in Search Console.
  2. Get an access token to authenticate your API call.
  3. Send requests to notify Google of new, updated, or deleted web pages.

我完成了步骤1,但是步骤2和3确实让我感到困惑.好像我需要通过编码获取OAuth令牌,但是我应该将这些代码放在哪里?对于使用API​​,他们向我展示了此示例:

I completed the step 1 but step 2 and 3 it really confuse me. Seem like I need obtain the OAuth token with coding but where do I put these code ? For using API, they show me this example :

POST https://indexing.googleapis.com/v3/urlNotifications:publish
{
  "url": "https://careers.google.com/jobs/google/technical-writer",
  "type": "URL_UPDATED"
}

再次,我不确定如何将这些块代码放在使用API​​的位置.有谁知道这一点可以逐步解释如何为我做这件事吗?最后一个问题:因为我的网站每天大约有10-15个新职位发布.每当有人发布新工作时,我可以通过某种方式设置此Indexing API自动向Google发送请求吗? 问候

Again, Im not sure where do I put these block code to using API. Can anyone know about this can explain step by step how to do it for me? Last question : because my website get around 10 - 15 new job post per day. Can I somehow set this Indexing API automatic send request to Google whenever someone post a new job ? Regards,

推荐答案

您应该在请求中将其作为承载认证标题传递.

You should be passing it as a Bearer authentication Header in your request.

授权:不记名

Authorization: Bearer

您也许还可以将它作为请求字符串的一部分传递,但我不记得它是否可以用于邮寄呼叫.

You may also be able to pass it as part as a request string I cant remember if this works with post calls though.

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 php客户端库它将为您处理大部分此类工作.他们在示例中此处

If you are using php you should consider using the Google php client library which will handle most of this for you. which is what they recommend in the example here

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

确保已正确设置服务帐户

Make sure you have set up the service account properly create service account

这篇关于Google Indexing API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆