Created
November 12, 2020 14:50
-
-
Save natzir/f72624656149d0cac59e33b938e2920b to your computer and use it in GitHub Desktop.
Google-API-Indexing.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Google-API-Indexing.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyOdc5P027WR+7q08wxfDCk2", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/natzir/f72624656149d0cac59e33b938e2920b/google-api-indexing.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Bp-PHfZO33Ly", | |
"outputId": "3b436e95-ae3e-4390-8cc8-4ec7aecc22e2", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
} | |
}, | |
"source": [ | |
"!npm install googleapis\n", | |
"!npm install request" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[K\u001b[?25h\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35msaveError\u001b[0m ENOENT: no such file or directory, open '/content/package.json'\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35menoent\u001b[0m ENOENT: no such file or directory, open '/content/package.json'\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No description\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No repository field.\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No README data\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No license field.\n", | |
"\u001b[0m\n", | |
"+ [email protected]\n", | |
"updated 1 package and audited 115 packages in 2.257s\n", | |
"\n", | |
"4 packages are looking for funding\n", | |
" run `npm fund` for details\n", | |
"\n", | |
"found \u001b[92m0\u001b[0m vulnerabilities\n", | |
"\n", | |
"\u001b[K\u001b[?25h\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35mdeprecated\u001b[0m [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142\n", | |
"\u001b[K\u001b[?25h\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35msaveError\u001b[0m ENOENT: no such file or directory, open '/content/package.json'\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35menoent\u001b[0m ENOENT: no such file or directory, open '/content/package.json'\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No description\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No repository field.\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No README data\n", | |
"\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m\u001b[35m\u001b[0m content No license field.\n", | |
"\u001b[0m\n", | |
"+ [email protected]\n", | |
"updated 1 package and audited 115 packages in 1.012s\n", | |
"\n", | |
"4 packages are looking for funding\n", | |
" run `npm fund` for details\n", | |
"\n", | |
"found \u001b[92m0\u001b[0m vulnerabilities\n", | |
"\n", | |
"\u001b[K\u001b[?25h" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "YkAylipg34fo", | |
"outputId": "a3d80d0c-6bd0-45f5-c9db-9a1195ed18f3", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
} | |
}, | |
"source": [ | |
"%%writefile index.js\n", | |
"\n", | |
"const request = require('request');\n", | |
"const {google} = require('googleapis');\n", | |
"const key = require('./service_account.json');\n", | |
"\n", | |
"const urlToIndex = 'https://www.analistaseo.es';\n", | |
"\n", | |
"const jwtClient = new google.auth.JWT(\n", | |
" key.client_email,\n", | |
" null,\n", | |
" key.private_key,\n", | |
" ['https://www.googleapis.com/auth/indexing'],\n", | |
" null\n", | |
");\n", | |
"\n", | |
"jwtClient.authorize(function (err, tokens) {\n", | |
" if (err) {\n", | |
" console.log(err);\n", | |
" return;}\n", | |
" const options = {\n", | |
" url: 'https://indexing.googleapis.com/v3/urlNotifications:publish',\n", | |
" method: 'POST',\n", | |
" headers: {\n", | |
" 'Content-Type': 'application/json'\n", | |
" },\n", | |
" auth: {\n", | |
" 'bearer': tokens.access_token\n", | |
" },\n", | |
" json: { \n", | |
" 'url': urlToIndex,\n", | |
" 'type': 'URL_UPDATED'\n", | |
" },\n", | |
" }\n", | |
" request(options, function (error, response, body) {\n", | |
" console.log(body);\n", | |
" });\n", | |
"});" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Overwriting index.js\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PhN5bWbI47Eb", | |
"outputId": "ecbcecf7-834c-421d-9fa6-87d2649bcda3", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
} | |
}, | |
"source": [ | |
"!node index.js" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" urlNotificationMetadata: {\n", | |
" url: \u001b[32m'https://www.analistaseo.es'\u001b[39m,\n", | |
" latestUpdate: {\n", | |
" url: \u001b[32m'https://www.analistaseo.es'\u001b[39m,\n", | |
" type: \u001b[32m'URL_UPDATED'\u001b[39m,\n", | |
" notifyTime: \u001b[32m'2020-11-12T14:49:42.289925234Z'\u001b[39m\n", | |
" }\n", | |
" }\n", | |
"}\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment