To connect with the Google Search Console API to automate your website's SEO reports, you'll need to use OAuth2.0 authentication to access the data. In this video, we'll show you a REALLY SIMPLE way to do that using Google Apps Script in less than 30 lines to code!
Google Apps Script: https://script.google.com/ Google Cloud Platform: https://console.cloud.google.com/
Link to the code: https://bootstrapping.tools/how-to-access-the-search-console-api-with-google-apps-script-using-oauth2/
function requestSearchConsoleAPI() {
const oauthToken = ScriptApp.getOAuthToken();
const siteUrl = 'sc-domain:YOUR_SITE_URL'
const url = 'https://www.googleapis.com/webmasters/v3/sites/'+ siteUrl + '/searchAnalytics/query'
const payload = {
startDate: "2022-01-01",
endDate: "2022-01-05",
dimensions: ["DATE"]
}
const headers = {
'Authorization': 'Bearer ' + oauthToken,
'Content-Type': 'application/json'
}
const options = {
headers: headers,
method: 'POST',
payload: JSON.stringify(payload)
}
const response = UrlFetchApp.fetch(url, options).getContentText()
const json = JSON.parse(response)
return json
}
}
🔔 Subscribe for more videos just like this: https://www.youtube.com/c/BootstrappingTools
🎉Are you interested in a Bootstrapping Tools Community? Let me know! https://forms.gle/4tzvffHiRqS7pVZY6 🎉

