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

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

我已经尝试了这个线程上的所有方法,但没有成功。

我正在尝试向 google API 发送一个非常简单的请求,以询问频道的信息。

我拥有的东西:

  1. 已安装 npm 请求
  2. A google API 密钥 - 导出到环境变量
  3. 我正在使用 cloud9(这就是为什么其他解决方案可能不起作用的原因)

我可以向雅虎天气发出请求API使用相同的方法没问题。

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

这是完整的错误

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

感谢您的帮助!

请试试这个。查询字符串参数未正确发送,因此 API 响应找不到您的密钥。

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