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
相关产品推荐
相关产品推荐

