Search code examples
node.jsgoogle-apiyoutube-apicloud9npm-request

Node.js Simple Google API Request: error:0906D06C:PEM routines:PEM_read_bio:no start line


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!


Solution

  • 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);
    });