1

I have tried everything on this thread with no luck. Node.js https pem error: routines:PEM_read_bio:no start line

I am trying to do a very simple request to the google API to ask for a channel's information.

Things I have:

  1. npm request installed
  2. A google API key - exported to an env variable
  3. I am using cloud9 (which is why the other solution may not have worked)

I can make a request to the yahoo weather API no problem using the same method.

var request = require('request');

request("https://www.googleapis.com/youtube/v3/channels?",{
    part: "snippet,contentDetails,statistics",
    id: "UCd534c_ehOvrLVL2v7Nl61w",
    key: process.env.YOUTUBE_API_KEY
}, function(err, response, body){
  if (err){
    console.log(err);
  }
  console.log(body);
});

Here is the full error

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Error (native)
at Object.createSecureContext (_tls_common.js:85:17)
at Object.exports.connect (_tls_wrap.js:1033:48)
at Agent.createConnection (https.js:82:22)
at Agent.createSocket (_http_agent.js:195:26)
at Agent.addRequest (_http_agent.js:157:10)
at new ClientRequest (_http_client.js:160:16)
at Object.exports.request (http.js:31:10)
at Object.exports.request (https.js:202:15)
at Request.start 
(/home/ubuntu/workspace/node_modules/request/request.js:748:32)
undefined

Thanks for the help!

hadro
  • 13
  • 5
  • Are you using API key to [authorize your request](https://developers.google.com/youtube/v3/docs/channels/list#auth)? Can you try to use OAuth instead, "authorization token that contains the https://www.googleapis.com/auth/youtubepartner-channel-audit scope". – ReyAnthonyRenacia Mar 25 '18 at 09:34

1 Answers1

0

Give this a try instead. The query string parameters are not sent correctly, so the API responds that it could not find your key.

var request = require('request');

request({url: "https://www.googleapis.com/youtube/v3/channels?",
         qs:{ part: "snippet,contentDetails,statistics",
              id: "UCd534c_ehOvrLVL2v7Nl61w",
              key: process.env.YOUTUBE_API_KEY
            }
}, function(err, response, body){
    if (err){
      console.log(err);
    }
    console.log(body);
});
Daniel
  • 542
  • 1
  • 4
  • 19