【问题标题】:Firebase Cloud Functions bitly example throwing errorFirebase Cloud Functions bitly 示例抛出错误
【发布时间】:2019-02-28 14:48:00
【问题描述】:

我正在按照 github 存储库中的示例来缩短链接 url

https://github.com/firebase/functions-samples/tree/Node-8/url-shortener

给出的错误如下

12:49:56.472米。 shortUrl 函数执行耗时 509 毫秒,完成 状态:'错误'12:49:56.464 a。米。缩短网址请求错误: 错误:getaddrinfo EAI_AGAIN api-ssl.bitly.com:443 在新的 RequestError (/srv/node_modules/request-promise-core/lib/errors.js:14:15) 在 Request.plumbing.callback (/srv/node_modules/request-promise-core/lib/plumbing.js:87:29) 在 Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31) 在 self.callback (/srv/node_modules/request/request.js:185:22) 在 emitOne (events.js:116:13) 在 Request.emit (events.js:211:7) 在 Request.onRequestError (/srv/node_modules/request/request.js:881:8) 在 emitOne (events.js:116:13) 在 ClientRequest.emit (events.js:211:7) 在 TLSSocket.socketErrorListener (_http_client.js:387:9) 在 emitOne (events.js:116:13) 在 TLSSocket.emit (events.js:211:7) 在 emitErrorNT (internal/streams/destroy.js:64:8) 在 _combinedTickCallback (内部/进程/next_tick.js:138:11) 在 process._tickDomainCallback (internal/process/next_tick.js:218:9)

我确实是函数新手,但我确实按照那里的文档中的所有步骤进行操作。

这是我的函数文件夹中的 index.js

const functions = require('firebase-functions');
const BitlyClient = require('bitly');
// TODO: Make sure to set the bitly.access_token cloud functions config using the CLI.
const bitly = BitlyClient(functions.config().bitly.access_token);

// Shorten URL written to /links/{linkID}.
exports.shortenUrl = functions.database.ref('/links/{linkID}').onCreate(async (snap) => {
  const originalUrl = snap.val();
  const response = await bitly.shorten(originalUrl);
  return snap.ref.set({
    original: originalUrl,
    short: response.data.url,
  })
});

还有我的 package.json 以便为 bitly 编译必要的

{
  "name": "url-shortener-functions",
  "description": "URL Shortener Firebase Functions sample",
  "dependencies": {
    "bitly": "^5.1.7",
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.5"
  },
  "devDependencies": {
    "eslint": "^4.13.1",
    "eslint-plugin-promise": "^3.6.0"
  },
  "scripts": {
    "lint": "./node_modules/.bin/eslint --max-warnings=0 .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "private": true
}

我也在我的函数文件夹中做了npm -install bitly,但仍然抛出该错误

我还按照文档说明在我的数据库中添加了链接

/functions-project-12345
    /links
        link-123456: "https://my.super.long-link.com/api/user/profile/-jEHitne10395-k3593085"

有什么线索吗?谢谢

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    它抱怨说它无法为远程主机解析:

    RequestError: Error: getaddrinfo EAI_AGAIN api-ssl.bitly.com:443
    

    因此,我假设需要 paid plan 才能执行此外部 API 调用。

    【讨论】:

    • 嗯,很奇怪,因为我生成了访问令牌,就像它从该文档中所说的那样
    • 也是我制作的第一个函数
    • @Todd 以及您对 Firebase 的计划;启用结算功能了吗?
    • @Todd 你不能进行这个调用,因为它是一个外部 API 调用。见上面的链接。它读取Outbound networking: Google services only(不包括bitly.com)。
    猜你喜欢
    • 2020-11-30
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 2018-06-17
    • 2021-09-27
    • 2019-02-04
    相关资源
    最近更新 更多