Instagram Graph API短期令牌转长期令牌失败:不支持GET请求
Instagram短期令牌兑换长期令牌报错"Unsupported request - method type: get"的解决办法
错误详情
你遇到的错误是调用长期令牌兑换接口时方法类型不被支持:
error: { message: 'Unsupported request - method type: get', type: 'IGApiException', code: 100, fbtrace_id: 'AnMYrIXYSTKYCA_Sh2qKxkU' }
问题根源
Instagram Graph API的ig_exchange_token接口(用于短期令牌转长期令牌)不支持GET请求,必须通过POST方式提交参数,参数不能放在URL查询字符串里。
修改后的代码
把GET请求改成POST,参数移到请求体中,格式和你获取短期令牌的逻辑保持一致:
const userPlatform = await this.userPlatformService.getUserPlatfromsByCode(userId, "INSTAGRAM"); // 修改后的长期令牌兑换请求配置 const userLongLiveTokenApi = { url: 'https://graph.instagram.com/access_token', method: 'post', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'ig_exchange_token', client_secret: instagramConfig.clientSecret, access_token: userPlatform.authToken }).toString() }; console.log(userLongLiveTokenApi); const userLongLiveTokenResponse = await this.apiCall(userLongLiveTokenApi);
关键改动点
- 请求方法从
'get'改为'post' - 移除URL中的查询参数,将参数通过
URLSearchParams序列化后放入请求体 - 添加
Content-Type: application/x-www-form-urlencoded请求头
内容的提问来源于stack exchange,提问作者Adil Shah
相关产品推荐
相关产品推荐

