Instant Indexing And Google Colab.research.google.com Notebook Uploading Codes
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "API Indexing For Blogger By Tushar",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"## **Instant Indexing For Blogger Website's Using Google API**"
],
"metadata": {
"id": "0uGYx5rzEjaJ"
}
},
{
"cell_type": "code",
"source": [
"#@title **Connect Your Google Drive**\n",
"#@markdown **To use this method, you have to connect your Google Drive everytime you Refresh/Disconnect/Reset this notebook in order to use the files saved in your drive but no need to re-upload the file again**\n",
"\n",
"#@markdown **Provide Yes > Execute the cell**\n",
"Connect_Google_Drive = \"Yes\" #@param [\"Yes\", \"No\"]\n",
"if Connect_Google_Drive == \"Yes\":\n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n",
" print(\"Successfully Connected!\")\n",
"else:\n",
" print(\"Not Connected!\")"
],
"metadata": {
"cellView": "form",
"id": "QqBWFgLlFQpF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title **Provide Complete Path Of The API Key Here**\n",
"API_Path = \"/content/drive/MyDrive/API_Key.json\" #@param {type:\"string\"}\n",
"\n",
"from oauth2client.service_account import ServiceAccountCredentials\n",
"import httplib2\n",
"\n",
"SCOPES = [\"https://www.googleapis.com/auth/indexing\"]\n",
"ENDPOINT = \"https://indexing.googleapis.com/v3/urlNotifications:publish\"\n",
"print('*'*50);print(\"Scopes & Endpoint Configured...\");print('*'*50);print(\"Adding Key...\");print('*'*50);\n",
"# service_account_file.json is the private key that you created for your service account.\n",
"JSON_KEY_FILE = API_Path\n",
"print(\"Key Added Successfully!\");print('*'*50);\n",
"credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)\n",
"http = credentials.authorize(httplib2.Http())\n",
"print(\"Credentials Successfully Authorized!\");print('*'*50);"
],
"metadata": {
"cellView": "form",
"id": "HgmMnKOBQcdR"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title **Provide Site URL & Update Request Type**\n",
"#@markdown Site URL will the exact URL you want to update or delete from the Google Search Index. **Also, please make a note that you have to provide URL only for the ownership verfied website. For any other URLs, it will not work.**\n",
"siteURL = \"\" #@param {type:\"string\"}\n",
"requestType = \"URL_UPDATED\" #@param [\"URL_UPDATED\", \"URL_DELETED\"]\n",
"content = str({'url':siteURL,'type':requestType})\n",
"print(\"RESULT:\");print('*'*50);print(\"URL and Update Request Type Configured!\");print('*'*50);\n",
"\n",
"response, content = http.request(ENDPOINT, method=\"POST\", body=content)\n",
"output = response['status']\n",
"\n",
"if output == '200':\n",
" print(\"Successfully Done!\");print('*'*50);\n",
"\n",
"else:\n",
" print(\"Error Code: {}\".format(output));print('*'*50);\n",
" print(\"Visit Here For More: https://developers.google.com/search/apis/indexing-api/v3/core-errors#api-errors\");\n",
" print('*'*50);"
],
"metadata": {
"cellView": "form",
"id": "VuJ-Pt1eS8mT"
},
"execution_count": null,
"outputs": []
}
]
}