Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

title and content is not being added to post BLOGGER #1139

Closed
m-afrasiab opened this issue Apr 30, 2018 · 11 comments
Closed

title and content is not being added to post BLOGGER #1139

m-afrasiab opened this issue Apr 30, 2018 · 11 comments
Assignees
Labels
needs more info This issue needs more information from the customer to proceed.

Comments

@m-afrasiab
Copy link

m-afrasiab commented Apr 30, 2018

I am having an issue with blogger api. When I try to publish a post to my blogger, the empty post got published. No title or content get included in it. Below is the code:

var express = require('express');
var app = express();
var request = require('request');
var rp = require('request-promise');
const google = require ('googleapis');
const Youtube = require("youtube-api");
const blogger = google.google.blogger('v3')
    , fs = require("fs")
    , readJson = require("r-json")
    , Lien = require("lien")
    , Logger = require("bug-killer")
    , opn = require("opn")
    , prettyBytes = require("pretty-bytes")
    ;
// I downloaded the file from OAuth2 -> Download JSON
const CREDENTIALS = readJson('./bcreds.json');
// Init lien server
let server = new Lien({
    host: "localhost"
  , port: 6111
});
// Authenticate
let oauth = Youtube.authenticate({
    type: "oauth"
  , client_id: CREDENTIALS.web.client_id
  , client_secret: CREDENTIALS.web.client_secret
  , redirect_url: CREDENTIALS.web.redirect_uris[0]
});
opn(oauth.generateAuthUrl({
    access_type: "offline"
  , scope: ["https://www.googleapis.com/auth/blogger"]
}));
// Handle oauth2 callback
server.addPage("/oauth2callback", lien => {
    Logger.log("Trying to get the token using the following code: " + lien.query.code);
    oauth.getToken(lien.query.code, (err, tokens) => {
        if (err) {
            lien.lien(err, 400);
            return Logger.log(err);
        }
        Logger.log("Got the tokens.");
        oauth.setCredentials(tokens);
        lien.end("The video is being uploaded. Check out the logs in the terminal.");

        blogger.posts.insert({
                auth: oauth,
                blogId: "7525914434133284870",
                resource: {
                  content: "postContent",
                  title: "postTitle",
                },  
            }, function(err, success){
                console.log(success);
            });
    });
});
@m-afrasiab m-afrasiab changed the title title and content is not being added to post title and content is not being added to post BLOGGER Apr 30, 2018
@JustinBeckwith
Copy link
Contributor

Greetings! I just gave this a shot over in #1140, and it appears to be working as expected. Are you sure the blog post is getting created at all? It looks like you're ignoring errors in the callback. I would change the callback to at least let you know if something else went wrong :)

 blogger.posts.insert({
  auth: oauth,
  blogId: "7525914434133284870",
  resource: {
    content: "postContent",
    title: "postTitle",
  },  
}, function(err, success) {
  if (err) {
    console.error('There was a problem creating the blog post!');
    console.error(err);
    return;
  }
  console.log(success);
});

Can you also share the output of success if this code executes correctly?

@JustinBeckwith JustinBeckwith self-assigned this Apr 30, 2018
@JustinBeckwith JustinBeckwith added the needs more info This issue needs more information from the customer to proceed. label Apr 30, 2018
@m-afrasiab
Copy link
Author

here is the output which I get: (it is clear in the output too that the field of the title and the content is empty even I have included in the code)

info  Trying to get the token using the following code: 4/AAAcK6ktF4u7BVcx3PJTi0
r4FLs44uPD30_jFtF7nns8QnfbjSb_Du46wavKZjjk6mi-jk2rvbhZoH_EVIm12KQ
info  Got the tokens.
{ kind: 'blogger#post',
  id: '6553035503261346515',
  blog: { id: '7525914434133284870' },
  published: '2018-04-30T11:45:00-07:00',
  updated: '2018-04-30T11:45:24-07:00',
  etag: '"tCegCRaUD_llG4Ci20eREslQYjU/dGltZXN0YW1wOiAxNTI1MTEzOTI0OTE4Cm9mZnNldD
ogLTI1MjAwMDAwCg"',
  url: 'http://crispypedia.blogspot.com/2018/04/blog-post_30.html',
  selfLink: 'https://www.googleapis.com/blogger/v3/blogs/7525914434133284870/pos
ts/6553035503261346515',
  title: '',
  content: '',
  author:
   { id: 'g112258697364094793999',
     displayName: 'Maher Afrasiab',
     url: 'https://www.blogger.com/profile/12057366759980641654',
     image:
      { url: '//lh5.googleusercontent.com/-Ny_v7lvs7ng/AAAAAAAAAAI/AAAAAAAAZgs/P
jsYDvjZ4m8/s35-c/photo.jpg' } },
  replies:
   { totalItems: '0',
     selfLink: 'https://www.googleapis.com/blogger/v3/blogs/7525914434133284870/
posts/6553035503261346515/comments' },
  status: 'LIVE',
  readerComments: 'ALLOW' }

@JustinBeckwith
Copy link
Contributor

Aiight, that's good at least. I'm sorry for asking this - but can you make 100% sure the title and content you're passing to the API isn't in fact blank? Just add a little console.log magic to make 100% sure?

Alright - a few other things to check:

  • What version of node.js are you running?
  • What version of googleapis is in your package.json?
  • Please verify YOU DO NOT have google-auth-library in your package.json.

@m-afrasiab
Copy link
Author

the node version is 8.10.0
googleapis version is 27.0.0
and I do not have google-auth-library in my package.json

@JustinBeckwith
Copy link
Contributor

Can you try upgrading to the latest version? I think we're on 29 now :)

@m-afrasiab
Copy link
Author

I have upgraded to latest version but still it is posting empty post to blogger.

@JustinBeckwith
Copy link
Contributor

I'm running out of ideas here 🤣 I merged #1140 earlier - can you clone the repo, and try running that sample?

@m-afrasiab
Copy link
Author

ok let me try

@m-afrasiab
Copy link
Author

I have run the sample and got this error
TypeError: Cannot read property 'data' of undefined at runSample (C:\Program Files\nodejs\proj\apv.js:19:19) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)

@m-afrasiab
Copy link
Author

Ok I have fixed it. Now it is working properly. thanks very much to you for your time and help.

@m-afrasiab
Copy link
Author

m-afrasiab commented Apr 30, 2018

I have question that, it would requires me to choose account for every single post. is it possible in anyway that I only have to select account in browser for only once for multiple posts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants