You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Instagram商业平台:短期Access Token转长期Token请求方法错误求助

Instagram长期Access Token获取失败:"不支持的请求 - 方法类型:get" 解决方法

问题详情

调用兑换长期Access Token接口时返回如下错误:

{
      "message": "Unsupported request - method type: get",
      "type": "IGApiException",
      "code": 100,
      "fbtrace_id": "AxWFZ9-0I6DhnjIelsjwYkk"
}

预期响应格式:

{
  "access_token":"<LONG_LIVED_ACCESS_TOKEN>",
  "token_type": "bearer",
  "expires_in": 5183944  // 令牌过期前的秒数
}

现有代码

获取短期Access Token代码

const result = await axios.post(
`https://api.instagram.com/oauth/access_token`,
      {
           client_id: IG_APP_ID,
           client_secret: IG_APP_SECRET,
           grant_type: "authorization_code",
           redirect_uri: `${PUBLIC_URL}/api/hunting/instagram/code`,
           code,
      },
      {
           headers: { "Content-Type": "application/x-www-form-urlencoded" },
      }
);

兑换长期Access Token代码(错误版本)

await axios.get(
    `https://graph.instagram.com/v21.0/access_token?grant_type=ig_exchange_token
    &client_secret=${IG_APP_SECRET}
    &access_token=${result.data.access_token}`
);

解决方案

核心问题:兑换长期Token的接口要求使用POST方法,而非GET,且参数需放在请求体中并设置正确的Content-Type头。

修改后的兑换代码:

await axios.post(
    `https://graph.instagram.com/v21.0/access_token`,
    {
        grant_type: "ig_exchange_token",
        client_secret: IG_APP_SECRET,
        access_token: result.data.access_token
    },
    {
        headers: { "Content-Type": "application/x-www-form-urlencoded" }
    }
);

说明

  • 已确认权限(instagram_business_basic、instagram_business_manage_messages等)配置正确,变量定义无误
  • 该接口从Graph API v21.0开始明确要求使用POST方法传递参数,GET请求会触发100号错误

内容的提问来源于stack exchange,提问作者Joshua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:42:41