Max*_*ard 5 instagram instagram-api
我正在尝试从Instagram获取access_token,以将其基本显示API用于新的应用程序(只需在网页上显示推文)。
我按照以下步骤操作:https : //developers.facebook.com/docs/instagram-basic-display-api/getting-started
但我陷入了第5步:将代码交换为令牌
cURL请求始终返回400错误,并显示以下消息:“找不到匹配代码或已经使用了匹配代码”
但是,经过多次测试,我只获得了一次access_token,但是它在大约一个小时后过期了。这似乎是非常随机的。
Instagram基本显示API似乎很新。前一段时间,我使用了在https://www.instagram.com/developer/网站上创建的应用程序,并且该程序过去一直有效。现在此站点显示此消息:
更新:从2019年10月15日开始,Instagram API平台上的新客户端注册和权限审查将终止,转而使用Instagram Basic Display API。
...以及指向developers.facebook.com的链接。
小智 11
我尝试按照原始文档使用命令行工具(https://developers.facebook.com/docs/instagram-basic-display-api/getting-started),但没有运气......
只需 3 个简单步骤即可完成以下操作:
https://api.instagram.com/oauth/access_token使用正文中的参数(而不是参数)发出 POST 请求。确保该x-www-form-urlencoded选项已启用。200 OK响应。access_tokenuser_id{
"access_token": "IGQVJYUXlDN...",
"user_id": 17841400...
}
Run Code Online (Sandbox Code Playgroud)
快乐的时光!!
请参阅屏幕截图以了解正确的设置:
小智 0
我也使用旧的 Instagram API。我必须更改一些内容才能使我的代码在新 API 上运行。不知道你用的是什么,我用 PHP 就是这样做的。
$url = 'https://api.instagram.com/oauth/access_token';
$fields = array(
'app_id' => 'YOUR_APP_ID',
'app_secret' => 'YOUR_APP_SECRET_ID',
'grant_type' => 'authorization_code',
'redirect_uri' => 'YOUR_REDIRECT_URL',
'code' => $code
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
//get the access token from the string sent from Instagram
$splitString = explode('"access_token":', $result);
$removeRest = explode(',', $splitString[1]);
$withSpace = str_replace('"','', $removeRest[0]);
$access_token = str_replace(' ','', $withSpace);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1730 次 |
| 最近记录: |