如何从Instagram获取我的近照?
我阅读了instargam API并在google中搜索了代码,但没有得到任何符合我要求的精确解决方案。我想在我的网站上展示我最近的照片,比如Facebook插件。我的图像看起来像- 我尝试了以下网址,但我得到的错误。你能查一下吗如何从Instagram获取我的近照?,instagram,instagram-api,Instagram,Instagram Api,我阅读了instargam API并在google中搜索了代码,但没有得到任何符合我要求的精确解决方案。我想在我的网站上展示我最近的照片,比如Facebook插件。我的图像看起来像- 我尝试了以下网址,但我得到的错误。你能查一下吗 https://api.instagram.com/v1/tags/nofilter/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d 及 请建议我如何显示我最近的照片看起来像上面
https://api.instagram.com/v1/tags/nofilter/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d
及
请建议我如何显示我最近的照片看起来像上面的截图
编辑:我有
Client ID
和Client Secreat
。让我知道哪一个是访问令牌?客户秘密:您的客户秘密
授权类型:授权代码是当前唯一支持的值
重定向uri:您在授权请求中使用的重定向uri。注意:该值必须与授权请求中的值相同。
代码:您在授权步骤中收到的确切代码。
阅读官方文件( )第一步:将您的用户引导至我们的授权URL;第二步:接收Instagram的重定向(这里是您获得的代码) 你可以查看官方页面。
我已经使用了此
API
请检查。我相信这会对你有所帮助
<?php
$access_token = 'YOUR_3rd_PARTY_ACCESS_TOKEN';
$user_id = 'INSTAGRAM_USER_ID';
$json_profile = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/?access_token={$access_token}");
$json = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/media/recent/?access_token=" . $access_token . "&count=9");
$a_json_profile = json_decode($json_profile, true);
$a_json = json_decode($json, true);
//echo "<pre>";
//print_r($json2);
//echo "</pre>"; exit;
$i = 0;
foreach ($a_json['data'] as $key => $value) {
//if ($i < 9) {
$a_images[$i]['link'] = $value['link'];
$a_images[$i]['url'] = $value['images']['thumbnail']['url'];
//$a_images[$value['id']]['caption'] = $value['caption']['text'];
$i++;
//}
}
shuffle($a_images);
$finalData = array('info'=>$a_json_profile, 'images'=>$a_images);
echo json_encode($finalData);
exit;
Instagram API返回一个JSON对象-您需要对其进行迭代以获取图像ID,然后自己创建布局。JSON中没有显示格式,只有图像大小选项。您的第二个URL是获取自己图像的正确端点,但您需要您的用户ID(编号)和正确的访问令牌(将采用第一个URL中的格式)。感谢您的帮助。此代码片段是请求访问令牌,而不是获取提要本身。
$apiData = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_uri,
'code' => $code
);
$apiHost = 'https://api.instagram.com/oauth/access_token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiHost);
curl_setopt($ch, CURLOPT_POST, count($apiData));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonData = curl_exec($ch);
curl_close($ch);
var_dump($jsonData);
$user = @json_decode($jsonData);
print_r($user);
<?php
$access_token = 'YOUR_3rd_PARTY_ACCESS_TOKEN';
$user_id = 'INSTAGRAM_USER_ID';
$json_profile = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/?access_token={$access_token}");
$json = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/media/recent/?access_token=" . $access_token . "&count=9");
$a_json_profile = json_decode($json_profile, true);
$a_json = json_decode($json, true);
//echo "<pre>";
//print_r($json2);
//echo "</pre>"; exit;
$i = 0;
foreach ($a_json['data'] as $key => $value) {
//if ($i < 9) {
$a_images[$i]['link'] = $value['link'];
$a_images[$i]['url'] = $value['images']['thumbnail']['url'];
//$a_images[$value['id']]['caption'] = $value['caption']['text'];
$i++;
//}
}
shuffle($a_images);
$finalData = array('info'=>$a_json_profile, 'images'=>$a_images);
echo json_encode($finalData);
exit;