"Error 400 encountered while trying to access the Google Blogger API

I'm encountering an issue while attempting to access Blogger through the JavaScript V3 API. Everything functions correctly when accessing my (public) test blog.

However, when I use the same code to access my (private) test blog, I encounter an error.

Here is the code snippet:

        var client_id = ['WWWW', 'XXXX'];
        var api_key = ['YYYY','ZZZZ'];
        var discoveryDocs = ['https://www.googleapis.com/discovery/v1/apis/blogger/v3/rest'];
        var scope = 'https://www.googleapis.com/auth/blogger.readonly';
        var blog_id = ['BLOG0', 'BLOG1'];

        var appendResults = function(results) {
          $('#results').append(JSON.stringify(results, undefined, 2) + '<hr/>');
        };

        getBlogs = function(client, key, blog) {
            gapi.client.init({
                'apiKey': key,
                'clientId': client,
                'discoveryDocs': discoveryDocs,
                'scope': scope
            }).then(function() {
                return gapi.client.blogger.posts.list({
                    'blogId': blog
                });
            }).then(function(d) {
                return d;
            }).then(function(response) {
                appendResults(response);
            }, function(reason) {
                appendResults(reason);
            });
        };

        gapi.load('client', function() {
            for(i=0; i<api_key.length; i++) {
                getBlogs(client_id[i], api_key[i], blog_id[i]);
            }
        });

The second element in api_key and blog_id corresponds to my private blog.

Here is the response I am receiving:

{
  "result": {
    "kind": "blogger#postList",
    "items": [
    ...
  ],
  "etag": "\"XXXX\""
}
...

and

{
  "result": {
    "error": {
    ...
  },
  ...
}

I have set up credentials in the developer console and accessing this through localhost:5000/, with localhost being a valid domain in the developer console.

The error message I receive suggests that the requesting origin may be invalid, but I cannot confirm this.

If I make the same private blog public and run the code again, it works for both blog IDs.

What could be the issue in my setup?

Answer №1

For Blogger API access to a private blog, it is essential to have an OAuth 2.0 token, as solely having an API key will not suffice. Refer to the documentation for more information.

Authorization is mandatory for private blog posts. However, if the blog is public, authorization is not required for accessing information.

When using OAuth tokens, the scope is different. Here is the OAuth 2.0 scope specifically for the Blogger API:

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

When requesting access through OAuth 2.0, your application must include the scope information provided by Google during application registration, such as the client ID and client secret.

Test the Blogger API using this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to make the onKeyDown event function properly in Next.js/React?

I'm currently developing a website with Next.js and am facing an issue trying to execute a simple function when a key is pressed. Strangely, the onKeyDown event isn't getting triggered as expected in my code snippet: <main onKeyDown={e => c ...

Is there a way to limit the rotation of an a-camera in aframe?

One scenario could be enabling rotation around the z-axis within a range of -70 to 70 degrees, or alternatively, preventing rotation around any arbitrary axis. Thank you! ...

Error: No @Directive annotation was found on the ChartComponent for Highcharts in Angular 2

I'm having trouble integrating Highcharts for Angular 2 into my project. After adding the CHART_DIRECTIVES to the directives array in @Component, I encountered the following error in my browser console: EXCEPTION: Error: Uncaught (in promise): No ...

CarouFredSel Transition Troubles

I am currently using CarouFredSel to create an image carousel, but I am encountering some issues with the transitions between items. My goal is to incorporate simple HTML elements into the carousel instead of just plain images. However, when I attempt to ...

Error encountered during the building of a Java project using Gradle

I ran into an issue with Git Bash error output (build failed). Despite attempting to resolve it by installing Python as suggested, setting the Python environment variable in IntelliJ, and following other recommendations, I still encounter the same build ...

How to keep the show/hide effect active in jQuery even when the user presses the backspace

I recently came across this code snippet on a fiddle: https://jsfiddle.net/htz8x1no/ that I'm working with. Here's the code in question: $('.relevant-results').hide(); $('#input').keyup(function() { if ($ ...

Using Jquery selectors along with variables to perform targeted search operations

I need assistance creating a JQuery selector that can automatically add an active class to a specific list item based on a variable. The variable sv will hold either 'dom-site' or 'int-site', which correspond to the id of a list item i ...

Encountering a Uncaught TypeError when attempting to split an undefined property, but issue is limited to certain pages

Recently, I've encountered an issue with iziModal on specific pages where I'm getting an error message. The error I'm facing is: Uncaught TypeError: Cannot read property 'split' of undefined at r.fn.init.t.fn.(anonymous fu ...

Exploring Next.js: Leveraging fetch to retrieve data in getServerSideProps and passing it to the client via query parameters

I'm utilizing a getServerSideProps function on the directory page. pages/catalog/index.js export async function getServerSideProps(ctx) { const response = await fetch( `http://someDomen.com/api/ipro/catalog?${ctx?.query?.page ? `page=${ctx.quer ...

Is commenting required? Well, meteor!

I am currently developing a chat application using Meteor and I am facing an issue where I want to require users to type something before sending a message (to prevent spamming by hitting enter multiple times). Unfortunately, I am unsure of how to achieve ...

The property was computed but cannot be set - specifically for a toggle component

I am currently working on developing a switch toggle component in Vue that includes a v-model and @updated. However, I am encountering difficulties when trying to update the model once the user toggles the switch. Initially, I faced an issue regarding muta ...

The component "react-native-snap-carousel" is having trouble displaying the card image

Recently, I started working with react native and encountered an issue while trying to implement the "react-native-snap-carousel". The carousel was functioning correctly with the data provided in the "carouselItems" array, but I faced difficulties with dis ...

yii2: Utilizing the power of dynamic calling in widgets

Imagine I have a widget called Widget1; In the view file, I call this widget like so: <?= Widget1::widget() ?> Clicking on an element should trigger a new instance of the widget and execute its JavaScript scripts. However, I am unable to get the s ...

How to Make a Zigzag Formation in three.js?

I have been working on developing a 3D tool and was in need of a zigzag structure. I managed to create it by iterating a function that produces 'V' multiple times, but now I am looking for a way to achieve the same effect using a single geometry ...

Retrieve the maximum numerical value from an object

My goal is to obtain the highest value from the scores object. I have a global object called "implementations": [ { "id": 5, "project": 'name project', "scores": [ { "id": 7, "user_id": 30, "implement ...

Getting a specific index from an array using the Angular ng-repeat Directive: A step-by-step guide

I am trying to retrieve a specific index in an array using the ng-repeat directive. Currently, it is displaying information for all indexes... I only want to display the information for the second index as an example... This is my main.js: app.controll ...

Which is better for creating contour graphs: JavaScript or PHP?

I need to create a scientific graph for a web application that displays temperature data based on time and depth coordinates. You can view an example here : I have time and depth coordinates, and I want to represent temperature using color in the graph, ...

incorporating theme.spacing in the declaration of the theme

The theme setup that I am working with is as follows: export const themeDefault = createTheme({ themeName: 'Default (Mortgage Hub)', spacing: 4, ...typography, palette, components: { MuiButton: { styleOverrides: { root ...

When employing useNavigation, the URL is updated but the component does not render or appear on the

Check out this code snippet: https://codesandbox.io/p/sandbox/hardcore-lake-mptzw3 App.jsx: import ContextProvider from "./provider/contextProvider"; import Routes from "./routes"; function App() { console.log("Inside App" ...

What is causing a single state update when setState is called twice in React?

It seems like I'm making a beginner mistake in React as I am trying to call the "addMessage" function twice within the "add2Messages" function, but it only registers once. I believe this issue might be related to how hooks work in React. How can I mod ...