Repository: swalker-888/google-indexing-api-bulk Branch: master Commit: 172d72596989 Files: 6 Total size: 4.2 KB Directory structure: gitextract_k27gau8_/ ├── .gitignore ├── README.md ├── index.js ├── package.json ├── service_account.json └── urls.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env # next.js build output .next # OS files .DS_Store ================================================ FILE: README.md ================================================ # google-indexing-api-bulk Created by Steve at [Journey Further SEO](https://www.journeyfurther.com/) Requires node.js - https://nodejs.org/en/download/ This script will help you index your website's pages in bulk, without having to manually request each URL for submission in the Search Console interface. First off you will need to set up access to the Indexing API in Google Cloud Platform - follow the instructions below. https://developers.google.com/search/apis/indexing-api/v3/prereqs Once you have access to Indexing API you'll be able to download a public/private key pair JSON file, this contains all of your credentials and should be saved as "service_account.json". Add the URLs to the urls.txt file that you need to be crawled/indexed. ## Verify site ownership in Search Console to submit URLs for indexing In this step, you'll verify that you have control over your web property. To verify ownership of your site you'll need to add your service account email address (see service_account.json - client_email) and add it as an owner ('delegated') of the web property in Search Console. You can find your service account email address in two places: - The client_email field in the JSON private key that you downloaded when you created your project. - The Service account ID column of the Service Accounts view in the Developer Console. - The email address has a format similar to the following: For example, "my-service-account@test-project-42.google.com.iam.gserviceaccount.com". Then... 1. Go to [Google Webmaster Central](https://www.google.com/webmasters/verification/home) 2. Click your verified property 3. Scroll down and click 'Add an owner'. 4. Add your service account email address as an owner to the property. ## Quotas 100 URLs per request batch 200 URLs per day ================================================ FILE: index.js ================================================ const fs = require('fs'); var request = require('request'); var { google } = require('googleapis'); var key = require('./service_account.json'); const jwtClient = new google.auth.JWT( key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/indexing'], null ); const batch = fs .readFileSync('urls.txt') .toString() .split('\n'); jwtClient.authorize(function(err, tokens) { if (err) { console.log(err); return; } const items = batch.map(line => { return { 'Content-Type': 'application/http', 'Content-ID': '', body: 'POST /v3/urlNotifications:publish HTTP/1.1\n' + 'Content-Type: application/json\n\n' + JSON.stringify({ url: line, type: 'URL_UPDATED' }) }; }); const options = { url: 'https://indexing.googleapis.com/batch', method: 'POST', headers: { 'Content-Type': 'multipart/mixed' }, auth: { bearer: tokens.access_token }, multipart: items }; request(options, (err, resp, body) => { console.log(body); }); }); ================================================ FILE: package.json ================================================ { "name": "bulk-indexing-api", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "fs": "0.0.1-security", "googleapis": "^46.0.0", "request": "^2.88.0" } } ================================================ FILE: service_account.json ================================================ // Download private key json file from https://console.developers.google.com/iam-admin/serviceaccounts and save here ================================================ FILE: urls.txt ================================================ // Add your URLs here