Easy way to send URL Request to Google Indexing API using PHP Script and Cron Jobs (RSS Feed or Manual)
Learn how to easily send URL requests to Google Indexing API using PHP Script and Cron Jobs. Quickly index your URLs in Google using RSS Feed or Manual method and improve your site's SEO.
Method 1: Automated Submission via Cron Jobs
collect.php : Fetches URLs from an RSS feed. Filters URLs based on isPermaLink="true" attribute in RSS feed XML. Saves the latest 20 unique URLs to private/new.json . Configuration: You need to set $rssUrl = 'https://yoursite/rss.xml' to your website's RSS feed URL. Also, check if isPermaLink is "true" or "false" in your RSS feed and update the code accordingly.
autoSubmit.php : Loads URLs from private/new.json . Loads previously submitted URLs from private/history.json . Submits only new URLs to Google Indexing API using a service account. Logs API responses and adds successfully submitted URLs to history.json . Limits history to the latest 60 URLs. Saves remaining URLs to private/new.json if any URL left that not submitted. Uses JWT (JSON Web Token) for authentication. Configuration: You need to have the service-account.json correctly placed in the private folder.
Cron Job Setup: You need to set up two cron jobs for each script. For collect.php , a cron job that runs periodically (e.g., hourly) to collect URLs. For autoSubmit.php , a cron job that runs periodically to submit URLs to the API. You recommended using site console.cron-job.org for both cron jobs.
project-root/
|--- private/
| |--- service-account.json
| |--- new.json
| |--- history.json
|
|--- collect.php
|--- autoSubmit.php
index.html : Provides a textarea for entering URLs (one per line). Uses JavaScript to fetch and post the URL data to submit.php . Displays the API response on the page.
submit.php : Receives a list of URLs from index.html . Submits the URLs to Google Indexing API using a service account. Returns the API response as JSON. Uses JWT for authentication. Configuration: You need to have the service-account.json correctly placed in the private folder.
project-root/
|--- private/
| |--- service-account.json
|
|--- index.html
|--- submit.php
Google Indexing API Setup: You must have already set up your Google Index API and have the service-account.json file. Authentication: Both methods use JWT for Google API authentication, based on the service account file. Error Handling: Basic error handling is included, which is important for troubleshooting. History: history.json in method 1 prevents duplicate submissions. Manual Submission: The manual submission method allows you to quickly submit many URLs at once.
service-account.json : Your Google service account key file. (Do not share this file publicly) collect.php : Fetches URLs from RSS feed and stores them in a JSON file. (For Method 1). autoSubmit.php : Submits URLs to the Google Indexing API and manages history. (For Method 1). new.json : Stores new URLs to be submitted. (For Method 1). history.json : Stores URLs that have already been submitted. (For Method 1). index.html : An HTML form for manually submitting URLs. (For Method 2). submit.php : Processes the URL submissions to Google Indexing API. (For Method 2).
Submitting URLs to Google Indexing API with Cron Jobs Run and Manual Methods all file download Zip format - https://owntweet.com/thread/233921
You can follow on Owntweet
What's Your Reaction?