php 社交instagram INSTAGRAM
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 社交instagram INSTAGRAM相关的知识,希望对你有一定的参考价值。
<?php
// use this instagram access token generator http://instagram.pixelunion.net/
$access_token="477798130.1677ed0.35cfa4837cd7437980b83d4fff154fb1";
$photo_count=9;
$json_link="https://api.instagram.com/v1/users/self/media/recent/?";
$json_link.="access_token={$access_token}&count={$photo_count}";
$json = file_get_contents($json_link);
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
foreach ($obj['data'] as $post) {
$pic_text=$post['caption']['text'];
$pic_link=$post['link'];
$pic_like_count=$post['likes']['count'];
$pic_comment_count=$post['comments']['count'];
$pic_src=str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
$pic_created_time=date("F j, Y", $post['caption']['created_time']);
$pic_created_time=date("F j, Y", strtotime($pic_created_time . " +1 days"));
echo "<div class='col-md-4 col-sm-6 col-xs-12 item_box'>";
echo "<a href='{$pic_link}' target='_blank'>";
echo "<img class='img-responsive photo-thumb' src='{$pic_src}' alt='{$pic_text}'>";
echo "</a>";
echo "<p>";
echo "<p>";
echo "<div style='color:#888;'>";
echo "<a href='{$pic_link}' target='_blank'>{$pic_created_time}</a>";
echo "</div>";
echo "</p>";
echo "<p>{$pic_text}</p>";
echo "</p>";
echo "</div>";
}
?>
————— instagram more than 33 больше 33
<?php
$instagram_access_token = get_field( 'instagram_access_token', 'option' );
$instagram_images_count = get_field( 'instagram_images_count', 'option' );
$access_token = $instagram_access_token;
if( !$instagram_images_count ){
$photo_count = 70;
}else{
$photo_count = $instagram_images_count;
}
$json_link = "https://api.instagram.com/v1/users/self/media/recent/?";
$json_link .= "access_token={$access_token}&count={$photo_count}";
$json = file_get_contents($json_link);
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
if( $photo_count > 33 )
{
$json = file_get_contents( $obj['pagination']['next_url'] );
$obj_page_2 = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
}
if( $photo_count > 66 )
{
$json = file_get_contents( $obj_page_2['pagination']['next_url'] );
$obj_page_3 = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
}
if( count($obj['data']) ):
?>
<div class="instagram-section">
<?php if( $instagram_block_title = get_field( 'instagram_block_title', 'option' ) ): ?><strong class="title"><span><?php echo $instagram_block_title; ?></span></strong><?php endif; ?>
<div class="instagram-feed-holder">
<a href="#" class="popup-open"><em class="circle"><span class="icon-arrow-bottom"></span></em></a>
<ul class="instagram-feed">
<?php
$counter = 0;
foreach ($obj['data'] as $post): ++$counter;
$pic_src = str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
$pic_text = $post['caption']['text'];
$pic_link = $post['link'];
?>
<li>
<a href="<?php echo $pic_link; ?>">
<img src="<?php echo $pic_src; ?>" alt="<?php echo $pic_text; ?>">
</a>
</li>
<?php if( $counter == 5 ){ break; } endforeach; ?>
</ul>
</div>
<ul class="instagram-feed">
<?php
global $feed_count;
foreach ($obj['data'] as $post): ++$feed_count;
$pic_src = str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
$pic_text = $post['caption']['text'];
$pic_link = $post['link'];
?>
<li>
<a href="<?php echo $pic_link; ?>">
<img src="<?php echo $pic_src; ?>" alt="<?php echo $pic_text; ?>">
</a>
</li>
<?php if( $feed_count == $photo_count ){ break; } endforeach; ?>
<?php
if( count($obj_page_2['data']) ):
foreach ($obj_page_2['data'] as $post): ++$feed_count;
$pic_src = str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
$pic_text = $post['caption']['text'];
$pic_link = $post['link'];
?>
<li>
<a href="<?php echo $pic_link; ?>">
<img src="<?php echo $pic_src; ?>" alt="<?php echo $pic_text; ?>">
</a>
</li>
<?php if( $feed_count == $photo_count ){ break; } endforeach; endif; ?>
<?php
if( count($obj_page_3['data']) ):
foreach ($obj_page_3['data'] as $post): ++$feed_count;
$pic_src = str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
$pic_text = $post['caption']['text'];
$pic_link = $post['link'];
?>
<li>
<a href="<?php echo $pic_link; ?>">
<img src="<?php echo $pic_src; ?>" alt="<?php echo $pic_text; ?>">
</a>
</li>
<?php if( $feed_count == $photo_count ){ break; } endforeach; endif; ?>
</ul>
</div>
<?php endif; ?>
—————————————————
<?php
$token = '281496136.ab103e5.60a81e7a32e4412498f35ce8d4d1770c';
$user_id = '281496136';
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/".$user_id."/media/recent/?access_token=".$token);
$result = json_decode($result);
if(!empty($result)):
?>
<div class="instagramm-gallery">
<h2><span><span><?php echo $this->__('SCS UNLIMITED ON INSTAGRAM'); ?></span></span></h2>
<div class="holder">
<img src="<?php echo $this->getSkinUrl('images/bg-instagramm.jpg'); ?>" alt="bg" class="bg" height="221" />
<div class="instagramm-carousel">
<div class="mask">
<div class="slideset">
<?php foreach ($result->data as $post): if($post->type == 'image'): ?>
<div class="slide">
<a href="<?php echo $post->images->standard_resolution->url; ?>" rel="lightbox">
<img src="<?php echo $post->images->standard_resolution->url; ?>" width="149" height="150" alt="image description" />
</a>
</div>
<?php endif; endforeach; ?>
</div>
</div>
<a class="btn-prev" href="#"><?php echo $this->__('Previous'); ?></a>
<a class="btn-next" href="#"><?php echo $this->__('Next'); ?></a>
</div>
</div>
</div>
<?php endif; ?>
以上是关于php 社交instagram INSTAGRAM的主要内容,如果未能解决你的问题,请参考以下文章
用于照片共享社交应用(如 Instagram)的 Mysql 查询字符串
php [instagram php] instagram api #social