【问题标题】:Using npm instagram-web-api on Heroku在 Heroku 上使用 npm instagram-web-api
【发布时间】:2020-10-25 17:35:01
【问题描述】:

我最近被介绍到 npm instagram-web-api 并决定尝试使用它来检索用户的 pfp。

const Instagram = require("instagram-web-api");
const insta = new Instagram({});
async function getpfp(userName){
    const user = await insta.getUserByUsername({ username: userName });
    return user.profile_pic_url;
}

这在本地工作得很好,但是当我尝试在 Heroku 上托管的应用程序中使用它时收到一个错误。

(node:4) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined
     at /app/node_modules/instagram-web-api/lib/index.js:152:34

我仍然不了解 Heroku 的所有细节,因此我们将不胜感激。

【问题讨论】:

    标签: node.js heroku instagram


    【解决方案1】:

    Promise 被拒绝,因为变量用户或用户属性未定义。要么你忘记在 Heroku 上设置环境变量,要么这个用户名不存在。您确定您的环境变量设置正确吗?

    【讨论】:

    • 我没有为此使用任何环境变量。在进一步研究之后,似乎 api 无法检索我提供的用户名的用户,尽管用户名肯定存在。我也尝试使用 node-insta-web-api 并遇到类似的问题。这两个都在本地工作,但在 Heroku 上没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多