【问题标题】:Node.js Simple Google API Request: error:0906D06C:PEM routines:PEM_read_bio:no start lineNode.js 简单的 Google API 请求:错误:0906D06C:PEM 例程:PEM_read_bio:没有开始行
【发布时间】:2018-09-03 02:45:42
【问题描述】:

我已经尝试了这个线程上的所有东西,但没有运气。 Node.js https pem error: routines:PEM_read_bio:no start line

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

我拥有的东西:

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

我可以使用相同的方法向 yahoo 天气 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

感谢您的帮助!

【问题讨论】:

标签: node.js google-api youtube-api cloud9 npm-request


【解决方案1】:

试试这个吧。查询字符串参数未正确发送,因此 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);
});

【讨论】:

    猜你喜欢
    • 2018-12-22
    • 2020-04-08
    • 1970-01-01
    • 2016-06-26
    • 2011-04-05
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多