According to the Docs, I authenticated my application on request calland tried to insert a message:
var blogger = google.blogger('v3');
app.post('/creatGoogleBloggerPost', function(req, res, next){
console.log('creatGoogleBloggerPost called');
var oauth2Client = new google.auth.OAuth2();
var key = require('./public_html/SoulSeeker2-1bxxxaaa727d.json');
var jwtClient;
jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/blogger'], null);
jwtClient.authorize(function(err, tokens) {
console.log('retrieved tokens.access_token from google', tokens.access_token);
google.options({
auth: jwtClient
});
if (err) {
console.log(err);
return;
} else {
blogger.posts.insert({
auth: jwtClient,
blogId: '4113791741191234135',
resource: {
title: 'Sample rootscope',
content: 'Content rootscope'
}
}, function(){
console.log('success');
});
}
});
});
I get the token back, and it also displays a callback success message, but, nevertheless, no mail is inserted when I check the blog. Also there is no error. What could be wrong here?
Update:
Actually google-blogger-apidoes not accept the service account token. So change my code to use oauth2.0with node-passport, but still getting login error:
blogger.posts.insert({
Authorization: 'Bearer ' +USERS.accessToken,
blogId: '4113796741591234135',
resource: {
title: 'Sample rootscope',
content: 'Content rootscope'
}
}, function(err, reponse){
if(err){
console.log('error ', err);
} else {
console.log('blog post success in google blogger' , reponse);
}
});
I passed auth token, but now I get the error:
error { [Error: Login Required]
code: 401,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Login Required',
locationType: 'header',
location: 'Authorization' } ] }
I am using the official google blogger api . I guess I don’t pass the token in the header. How to transfer a token in order to fix this problem?