Instagram API 2019 Access令牌每2小时过期一次

问题描述 投票:0回答:1

截至2019年10月21日,Instagram阻止您从Instagram内部创建和管理客户,并且现在所有内容都通过Facebook Developer管理,对此没有真正的问题...

在我的情况下,只需要显示一个用户个人资料图像。我很快就开始工作了,但是访问令牌每2个小时过期一次,然后我需要再次对其进行重新授权...这从来就不是问题...您授权一次就可以了。

使用此工作代码:

function fetchData($url){
  $inst = curl_init($url);
  curl_setopt($inst, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($inst, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($inst, CURLOPT_SSL_VERIFYPEER, 0);
  $output = curl_exec($inst);
  curl_close($inst);

  return $output;
}

$insta_access_token = 'MY_ACCESS_TOKEN';
$insta_count = '6';

$instagram_result = fetchData("https://graph.instagram.com/me/media?fields=id,username,media_url&access_token={$insta_access_token}&count={$insta_count}");
$instagram_result = json_decode($instagram_result);
print_r($instagram_result);

这可以正常工作,直到访问令牌过期。

我在这里完全没有使用API​​时看到了其他窍门:How can I get a user's media from Instagram without authenticating as a user?

[这使用PHP提取配置文件内容,这是我的研究中唯一显示来自单一使用配置文件的基本图像库的可行解决方案:

$html = file_get_contents('https://instagram.com/apple/');
preg_match('/_sharedData = ({.*);<\/script>/', $html, $matches);
$profile_data = json_decode($matches[1])->entry_data->ProfilePage[0]->graphql->user;

我是否丢失了某些东西,或者一旦对基本图像进行了一次身份验证,就无法保持有效的访问令牌运行?

干杯。

php instagram instagram-api instagram-graph-api
1个回答
0
投票

[您需要做的是通过向此终结点发出GET请求来延长访问令牌的持续时间(根据我所知,长寿命的访问令牌在60天内很有价值)

url = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&%20client_id='Your_App_Id'&client_secret='Your_App_secret'&fb_exchange_token='Your_Short_Lived_Access_token''
© www.soinside.com 2019 - 2024. All rights reserved.