简体   繁体   English

AXIOS 对 instagram 的 GET 请求在产品中不起作用

[英]AXIOS GET request to instagram not working in prod

I am stuck for a few hours and I can't find an answer.我被困了几个小时,我找不到答案。

It's a very simple request that works fine in the browser (it returns a JSON answer), for example: https://www.instagram.com/eurosportfr/channel/?__a=1这是一个非常简单的请求,在浏览器中运行良好(它返回 JSON 答案),例如: https://www.instagram.com/eurosportfr/channel/?__a=1

In dev the code:在开发代码中:

const express = require('express');
const axios = require('axios');
const cors = require('cors');

const app = express();

app.use(cors());

app.get('/instagram', (req, res) => {
 
  async function getInstagramFeed() {
    await axios
      .get('https://www.instagram.com/eurosportfr/?__a=1')
      .then((response) => {
        console.log(response);
        res.write(`${JSON.stringify(response.data)}`);
        res.end();
      })
      .catch((err) => {
        console.log(err.response);
        res.write('<h1>ERROR GRAVE</h1>');
        res.write(err.response);
        res.end();
      });
  }

  getInstagramFeed();
});

const PORT = process.env.PORT || 8000;
app.listen(PORT, () => console.log(`listening on ${PORT}`));

The result in DEV ENV is JSON data with all what I need. DEV ENV 中的结果是 JSON 数据以及我需要的所有数据。

But in production, it doesn't return me the JSON.但在生产中,它不会返回 JSON。 Instead it returns me an HTML page...相反,它返回给我一个 HTML 页面......

You can try it here: (I display in the body the result) https://corsmiddleware.vercel.app/instagram你可以在这里试试:(我在正文中显示结果) https://corsmiddleware.vercel.app/instagram

When I try another api request with another API client, it works just fine in prod, example: https://corsmiddleware.vercel.app/test当我使用另一个 API 客户端尝试另一个 api 请求时,它在产品中工作得很好,例如: https://corsmiddleware.vercel.app/test

Any idea??任何想法??

Thanks谢谢

This request now requires authentification.此请求现在需要身份验证。 It was working in the past, and it's still actually working here in Morocco where I am, but this solution is not reliable.它过去有效,现在仍在我所在的摩洛哥工作,但这种解决方案并不可靠。

The solution is to follow the instructions on facebook: https://developers.facebook.com/docs/instagram-basic-display-api/解决方法是按照 facebook 上的说明进行操作: https://developers.facebook.com/docs/instagram-basic-display-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM