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?