React JS Cors -Origin -Instagram基本显示API

发布于 2025-02-10 00:17:01 字数 928 浏览 4 评论 0 原文

我对 cors有问题:访问控制尝试从Instagram API交换代码以访问代码时。

Instagram api文档步骤5: https://developers.facebook.com/docs/instagram-basic-display-api-api/getting-started#step-5--xchange-change-change-change-change-change-code-for-a-token < /a>

身体参数:

const body = {
    'client_id': 'xxxxxxxxxxxxxx',
    'client_secret': 'xxxxxxxxxxxxxx',
    'grant_type': 'authorization_code',
    'redirect_uri': 'https://localhost:3000/',
    'code': instaCode
};

我的请求:

axios.post(`https://api.instagram.com/oauth/access_token`, qs.stringify(body), { 
     headers: {'content-type': 'application/x-www-form-urlencoded'} 
});

码在2个月前工作。

I have problem with CORS: Access-Control-Allow-Origin when try to exchange the code for access token from Instagram API.

Instagram API documentation Step 5 : https://developers.facebook.com/docs/instagram-basic-display-api/getting-started#step-5--exchange-the-code-for-a-token

Body parameters:

const body = {
    'client_id': 'xxxxxxxxxxxxxx',
    'client_secret': 'xxxxxxxxxxxxxx',
    'grant_type': 'authorization_code',
    'redirect_uri': 'https://localhost:3000/',
    'code': instaCode
};

My request:

axios.post(`https://api.instagram.com/oauth/access_token`, qs.stringify(body), { 
     headers: {'content-type': 'application/x-www-form-urlencoded'} 
});

Тhis code worked 2 months ago.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦上情书 2025-02-17 00:17:01

编辑:您可以尝试此 axios post post request以发送表单数据首先这似乎更好,下面对我有用

,尽管您必须以表格数据发送身体。

我相信Fetch API会起作用,但是自节点17以来就可以使用,如果您使用的是较早版本,这对我有用。

来源

const { post } = require("request");
const { promisify } = require("util");


const postAsync = promisify(post);

    const form = {
        client_id: NUMBER,
        client_secret: STRING,
        grant_type: "authorization_code",
        redirect_uri: STRING,
        code: req.body.code,
    };

    let { body, statusCode } = await postAsync({
        // let result = await postAsync({
        url: "https://api.instagram.com/oauth/access_token",
        form,
        headers: {
            "content-type": "multipart/form-data",
            host: "api.instagram.com",
        },
    });

npm我要求
当然可以在尝试/捕获中使用它

edit: you can try this axios post request to send form data first which seems better, below worked for me though

That won't work, you have to send the body in a form data.

I believe fetch API would work but that's available since node 17, if you're using earlier version this is what worked for me.

SOURCE https://www.section.io/engineering-education/integrating-instagram-basic-display-api/

const { post } = require("request");
const { promisify } = require("util");


const postAsync = promisify(post);

    const form = {
        client_id: NUMBER,
        client_secret: STRING,
        grant_type: "authorization_code",
        redirect_uri: STRING,
        code: req.body.code,
    };

    let { body, statusCode } = await postAsync({
        // let result = await postAsync({
        url: "https://api.instagram.com/oauth/access_token",
        form,
        headers: {
            "content-type": "multipart/form-data",
            host: "api.instagram.com",
        },
    });

npm i request
and use that inside a try/catch of course

梦回梦里 2025-02-17 00:17:01

我浪费了3天的错误,但终于找到了解决方案。

您无法从前端侧处理它,因为Instagram API仅接受一种媒介的请求,为此,您必须在后端部署API才能解决此问题。

一旦您将API部署在后端,后端将要求访问访问权限,您的问题将得到解决。

I have wasted 3 days on this error but finally got the solution.

You cannot handle it from front-end side because Instagram API only accepts requests from one medium and for that you will have to deploy your API at backend to resolve this issue.

Once you will deploy the API at backend and backend will request for the access_token , your issue will be resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文