Featured Post

Elon Musk’s Influence on the 2024 Presidential Election and Its Potential Outcomes

  In the upcoming 2024 U.S. presidential election, the influence of tech moguls like Elon Musk is a point of significant interest. Musk, with his vast following, has demonstrated an ability to sway public opinion through his business decisions, public statements, and presence on social media platforms like X (formerly Twitter). The effect Musk’s actions may have on the election—and candidates such as Donald Trump—is worth examining as he becomes a key player in the larger landscape of digital influence. Elon Musk and Digital Influence in Politics A Shift in Public Influence Musk’s reach extends beyond business; he is now a major influencer in political spheres. By acquiring X, Musk gained direct access to one of the most influential social media platforms in the world, where he regularly engages with a diverse audience. His unpredictable political stances and commentary resonate with millions, and his platform decisions have the potential to shape public opinion. Musk’s Public Poli...

Using Blogger API with Google Apps Script

 You can use Google Apps Scripts to administer your Blogger blogs, just like you can with WordPress. You must add the Apps Script oAuth2 library to your Google Apps script project and enable the Blogger API from your Google Developers panel. Depending on whether you wish to have read-only or write-only access to blogs, the scope should be set to one of the following. 

https://www.googleapis.com/auth/blogger
https://www.googleapis.com/auth/blogger.readonly


The code snippet establishes a connection with the Blogger API and retrieves a list of the blogs that the currently authorized users have on Blogger. The blog's ID, name, and URL are then output in the console log.


function bloggerAPI() {
  var api = 'https://www.googleapis.com/blogger/v3/users/self/blogs';

  var headers = {
    Authorization: 'Bearer ' + getService().getAccessToken(),
  };

  var options = {
    headers: headers,
    method: 'GET',
    muteHttpExceptions: true,
  };

  var response = UrlFetchApp.fetch(api, options);

  var json = JSON.parse(response.getContentText());

  for (var i in json.items) {
    Logger.log('[%s] %s %s', json.items[i].id, json.items[i].name, json.items[i].url);
  }
}

The title and text of a blog post are updated through script in the following example utilizing the Blogger API. Through Patch Semantics, which enables us to deliver only the fields that have changed or require updating, we update the post. We make an HTTP POST request and set the override X-HTTP-Method-Override header to PATCH because UrlFetchApp disallows HTTP PATCH queries.

function updatePost(blogID, postID) {
  var url = 'https://www.googleapis.com/blogger/v3/blogs/' + blogID + '/posts/' + postID;

  var payload = {
    title: 'This is the post title',
    content: 'This is **HTML** post',
  };

  var headers = {
    Authorization: 'Bearer ' + getService().getAccessToken(),
    'X-HTTP-Method-Override': 'PATCH',
  };

  var options = {
    headers: headers,
    method: 'POST',
    muteHttpExceptions: true,
    payload: JSON.stringify(payload),
    contentType: 'application/json',
  };

  var response = UrlFetchApp.fetch(url, options);

  Logger.log(response.getContentText());
}

Troubleshooting: If you fetching the post status (draft, live or scheduled), you need to set the view parameter as “ADMIN” in the API call.

For 403 forbidden errors that say “We’re sorry, but you don’t have permission to access this resource” - it is likely that you have only read-only or view access to a blog.

Comments