关键词搜索

全站搜索
×
密码登录在这里
×
注册会员

已有账号? 请点击

忘记密码

已有账号? 请点击

使用其他方式登录

google indexing提交索引接口的坑解决办法

发布2021-03-18 浏览2149次

详情内容

在用thinkphp做google indexing提交索引接口时,一直提示403错误 ,一直都是按接口文档做:

在看了国外的文档:https://support.google.com/webmasters/thread/4763732?hl=en

https://developers.google.com/search/apis/indexing-api/v3/prereqs#php

就是不行,原因分析是没有添加域名权限。

$url = input('url');
//API: https://github.com/googleapis/google-api-php-client
//https://github.com/googleapis/google-api-php-client/blob/master/docs/oauth-web.md#create-authorization-credentials
$client = new \Google_Client();
$json = dirname(__DIR__). '/'.'api-project-463346309290-445a4b1bbd93.json';

// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig($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\": \"$url\",
  \"type\": \"URL_UPDATED\"
}";

$response = $httpClient->post($endpoint, [ 'body' => $content ]);
//$response = json_encode($response);
$status_code = $response->getStatusCode();
if($status_code==200)
{
    Db::name('sitemap')->where('url',$url)->update(['google_indexing'=>1]);
    $this->success('成功提交Google');
}
else
{
    $this->error('接口错误'.$status_code);
}

解决方法是在新版控制台添加生成的证书邮箱后https://search.google.com/search-console/,是不行的,还是要在旧版网站管理中心添加域名和生成的邮箱:https://www.google.com/webmasters/verification/home?

image.pngimage.pngimage.png

点击QQ咨询
开通会员
上传资源赚钱
返回顶部
×
  • 微信支付
  • 支付宝付款
扫码支付
微信扫码支付
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载