npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-search-api

v1.1.5

Published

提供Search Console API 和 Indexing API系列使用方法,可用于主动推送站点地图等数据,提高谷歌收录效率。

Downloads

27

Readme

google-search-api for Google Search Console

提供 Search Console API 和 Indexing API 系列工具方法,可用于在网站更新或者发布时主动告知 Google 当前站点的网站地图或者已更新的页面列表等,加快Google的收录效率。

使用 google-search-api 的前提条件

  1. 拥有 Google 帐号
  2. Google Search Console 中添加站点资源,并已验证站点所有权;
  3. 添加 wibetter 服务账号([email protected]),并授予“拥有者”权限。

使用方法

google search api 使用方法

特别说明

  1. wibetter 服务账号 仅用于测试和验证「非正式站点」的「谷歌搜索收录推送服务」效果;
  2. 正式站点请在「Google Cloud」创建您自己的服务账号,点击创建服务账号;
  3. 国内网络环境,获取google search api的token会失败,请使用外网环境(比如在国内可使用香港机房,确保能正常连接国外网络环境);

google-search-api的使用方法

1. 安装:

$ npm install --save-dev google-search-api

或者:

$ yarn add google-search-api --dev

2. 向 Google Search Console 推送站点页面地址

import {updateSite} from 'google-search-api';
/**
 * 先获取 google search api token,再执行工具方法
 * 备注1: client_email, private_key 从 google cloud 服务账号中获取
 * 备注2: 当前示例的 client_email, private_key 从 demo/service_account.json 中获取
 */ 
const tokenInfo = await getAuthToken(client_email, private_key);
const result = await updateSite('https://www.wibetter.online/aigc85f4', tokenInfo.access_token);

3. 向 Google Search Console 批量推送站点页面地址列表

import {indexingBatch} from 'google-search-api';
// 先获取 google search api token
const tokenInfo = await getAuthToken(client_email, private_key);
const result = await indexingBatch(['https://www.wibetter.online/aigc85f4', 'https://www.wibetter.online/aigcd334'], tokenInfo.access_token);

4. 向 Google Search Console 推送站点地图

import {sumbitSiteMap} from 'google-search-api';
// 先获取 google search api token
const tokenInfo = await getAuthToken(client_email, private_key);
const result = await sumbitSiteMap(
  'https://www.wibetter.online/',
  'https://www.wibetter.online/sitemap.xml',
  tokenInfo.access_token
);

5. 查询站点推送情况,可用于检测主动推送是否生效

import {sumbitSiteMap} from 'google-search-api';
// 先获取 google search api token
const tokenInfo = await getAuthToken(client_email, private_key);
const result1 = await checkSite('https://www.wibetter.online/', tokenInfo.access_token);

返回结果说明

返回结果格式如下

{
  status: 'error/success',
  code: 200,
  codeMsg: '请求执行成功',
  message: 'xxx'
}

code 说明

code | 说明 :---:|:---: 401 | 获取token失败,请检查服务授权配置是否正确。 403 | 暂无权限,可能原因:未添加站点资源 / 服务账号未授权 / 站点资源和域名不匹配。 429 | 请求超过配额限制。 404 | 找不到与该请求关联的资源。 200 | 请求执行成功。

更多 code 说明,请查看标准错误消息