How to Use Bing IndexNow with Blogger
How to Use Bing IndexNow with Blogger
Bing IndexNow allows websites to quickly index their new content. In this article, we will explain in detail how Blogger users can utilize IndexNow.
1. Required Information
- API Key: Obtain this from the Bing Webmaster tool.
- Site URL: This is your blog's URL.
2. Sending URLs with Google Apps Script
The following code will be used to send URLs from your RSS feed to Bing:
function submitUrlBatch() {
var apiKey = 'YOUR_API_KEY'; // Enter your API key here
var siteUrl = 'https://yourblog.blogspot.com'; // Your blog's URL
var rssSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RSS');
var sentSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sent');
if (!sentSheet) {
sentSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('Sent');
}
var sentUrls = sentSheet.getRange('A1:A' + sentSheet.getLastRow()).getValues().flat();
var lastRow = rssSheet.getLastRow();
var urls = rssSheet.getRange(2, 2, lastRow - 1, 1).getValues();
var xmlPayload = `
${siteUrl}
`;
var sendCount = 0;
for (var i = 0; i < urls.length; i++) {
var url = urls[i][0];
if (url && sentUrls.indexOf(url) === -1) {
xmlPayload += `${url} `;
sentSheet.getRange(sentSheet.getLastRow() + 1, 1).setValue(url);
sendCount++;
}
}
if (sendCount > 0) {
xmlPayload += ` `;
var options = {
'method': 'POST',
'contentType': 'application/xml; charset=utf-8',
'payload': xmlPayload,
'headers': {'apikey': apiKey},
'muteHttpExceptions': true
};
var url = 'https://ssl.bing.com/webmaster/api.svc/pox/SubmitUrlBatch?apikey=' + apiKey;
var response = UrlFetchApp.fetch(url, options);
}
}
3. Fetching the RSS Feed
The following code will be used to fetch your blog's RSS feed:
function fetchRSSFeed() {
var sheetName = 'RSS';
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName);
if (!sheet) {
sheet = spreadsheet.insertSheet(sheetName);
}
var rssUrl = 'https://yourblog.blogspot.com/feeds/posts/default';
var response = UrlFetchApp.fetch(rssUrl);
var xml = response.getContentText();
var document = XmlService.parse(xml);
var root = document.getRootElement();
var atomNS = XmlService.getNamespace('http://www.w3.org/2005/Atom');
var entries = root.getChildren('entry', atomNS);
sheet.clear();
sheet.getRange(1, 1).setValue('Title');
sheet.getRange(1, 2).setValue('URL');
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var title = entry.getChild('title', atomNS).getText();
var links = entry.getChildren('link', atomNS);
var linkUrl = '';
for (var j = 0; j < links.length; j++) {
if (links[j].getAttribute('rel').getValue() == 'alternate') {
linkUrl = links[j].getAttribute('href').getValue();
break;
}
}
sheet.getRange(i + 2, 1).setValue(title);
sheet.getRange(i + 2, 2).setValue(linkUrl);
}
}
4. Implementation
Copy and paste the above codes into the Apps Script editor in Google Sheets, and run the functions to send URLs to Bing. This will help ensure that your blog's new content is indexed quickly.
Comments
Post a Comment