Wednesday, 19 April 2017

How to insert posts using blogger api nodejs

According to Docs, I have authenticated my app on request call and try to insert a post:

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/analytics.readonly'], 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 am getting the token back and also it prints the call back success message but however, no post is inserted when I check the blog. There is no error either. What could be wrong here?



via kittu

No comments:

Post a Comment