我需要獲取一些圖片,其中使用PHP的具體標籤? 任何幫助將是真棒,或提示?從Instagram獲取所有的照片,其中有一個與PHP的具體井號標籤
回答
有一個instagram公共API的標籤部分,可以幫助你做到這一點。 http://instagram.com/developer/endpoints/tags/
這裏是我寫的一個,而前一個例子:
<?php
// Get class for Instagram
// More examples here: https://github.com/cosenary/Instagram-PHP-API
require_once 'instagram.class.php';
// Initialize class with client_id
// Register at http://instagram.com/developer/ and replace client_id with your own
$instagram = new Instagram('CLIENT_ID_HERE');
// Set keyword for #hashtag
$tag = 'KEYWORD HERE';
// Get latest photos according to #hashtag keyword
$media = $instagram->getTagMedia($tag);
// Set number of photos to show
$limit = 5;
// Set height and width for photos
$size = '100';
// Show results
// Using for loop will cause error if there are less photos than the limit
foreach(array_slice($media->data, 0, $limit) as $data)
{
// Show photo
echo '<p><img src="'.$data->images->thumbnail->url.'" height="'.$size.'" width="'.$size.'" alt="SOME TEXT HERE"></p>';
}
?>
獲得超過20,你可以使用負載更多的按鈕。
的index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Instagram more button example</title>
<!--
Instagram PHP API class @ Github
https://github.com/cosenary/Instagram-PHP-API
-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
ul {
width: 950px;
}
ul > li {
float: left;
list-style: none;
padding: 4px;
}
#more {
bottom: 8px;
margin-left: 80px;
position: fixed;
font-size: 13px;
font-weight: 700;
line-height: 20px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#more').click(function() {
var tag = $(this).data('tag'),
maxid = $(this).data('maxid');
$.ajax({
type: 'GET',
url: 'ajax.php',
data: {
tag: tag,
max_id: maxid
},
dataType: 'json',
cache: false,
success: function(data) {
// Output data
$.each(data.images, function(i, src) {
$('ul#photos').append('<li><img src="' + src + '"></li>');
});
// Store new maxid
$('#more').data('maxid', data.next_id);
}
});
});
});
</script>
</head>
<body>
<?php
/**
* Instagram PHP API
*/
require_once 'instagram.class.php';
// Initialize class with client_id
// Register at http://instagram.com/developer/ and replace client_id with your own
$instagram = new Instagram('ENTER CLIENT ID HERE');
// Get latest photos according to geolocation for Växjö
// $geo = $instagram->searchMedia(56.8770413, 14.8092744);
$tag = 'sweden';
// Get recently tagged media
$media = $instagram->getTagMedia($tag);
// Display first results in a <ul>
echo '<ul id="photos">';
foreach ($media->data as $data)
{
echo '<li><img src="'.$data->images->thumbnail->url.'"></li>';
}
echo '</ul>';
// Show 'load more' button
echo '<br><button id="more" data-maxid="'.$media->pagination->next_max_id.'" data-tag="'.$tag.'">Load more ...</button>';
?>
</body>
</html>
ajax.php
<?php
/**
* Instagram PHP API
*/
require_once 'instagram.class.php';
// Initialize class for public requests
$instagram = new Instagram('ENTER CLIENT ID HERE');
// Receive AJAX request and create call object
$tag = $_GET['tag'];
$maxID = $_GET['max_id'];
$clientID = $instagram->getApiKey();
$call = new stdClass;
$call->pagination->next_max_id = $maxID;
$call->pagination->next_url = "https://api.instagram.com/v1/tags/{$tag}/media/recent?client_id={$clientID}&max_tag_id={$maxID}";
// Receive new data
$media = $instagram->getTagMedia($tag,$auth=false,array('max_tag_id'=>$maxID));
// Collect everything for json output
$images = array();
foreach ($media->data as $data) {
$images[] = $data->images->thumbnail->url;
}
echo json_encode(array(
'next_id' => $media->pagination->next_max_id,
'images' => $images
));
?>
instagram.class.php
查找功能getTagMedia()和替換爲:
public function getTagMedia($name, $auth=false, $params=null) {
return $this->_makeCall('tags/' . $name . '/media/recent', $auth, $params);
}
這很好用! +1如果你有時間,你可以看看我有類似的問題嗎? http://stackoverflow.com/questions/17487231/input-value-in-ajax-call-does-not-work –
似乎有人設法回答更快,所以我想它已經解決了。 – kexxcream
是的,顯然。不管怎麼說,還是要謝謝你! –
如果你只需要顯示基於標籤的圖像,那麼不包括包裝類「instagram.class.php」。由於媒體& Instagram API中的標籤端點不需要認證。您可以使用以下基於curl的功能根據您的標籤檢索結果。
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$tag = 'YOUR_TAG_HERE';
$client_id = "YOUR_CLIENT_ID";
$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;
$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);
//Now parse through the $results array to display your results...
foreach($results['data'] as $item){
$image_link = $item['images']['low_resolution']['url'];
echo '<img src="'.$image_link.'" />';
}
我設置了PHP代碼可以在情況下幫助您要訪問Instagram的圖像,而API的主題標籤的基礎上
自2015年11月17日,你必須進行身份驗證的用戶製作任何(甚至諸如「獲得具有特定主題標籤的一些照片」)請求。見the Instagram Platform Changelog:於2015年11月17日或之後創建
應用: 所有API端點需要一個有效的access_token。 2015年11月17日之前創建的 應用: 不受新的API的行爲,直到6月1日,2016年
現在這使得2016不再有用的6月1日之前,這裏給出所有答案。
,但你可以得到「獲得一些具有特定標籤的圖片」[不需要API](http://stackoverflow.com/questions/40542335/how-to-get-all-images-of-hashtag-in -instagram-without-api) – machineaddict
2017,我仍然可以在沒有訪問令牌的情況下獲取數據。示例:https://www.instagram.com/salvun/media/ – redochka
我如何在我的android應用程序中使用各種主題標籤獲取帖子? –
- 1. 從instagram獲取所有用戶照片
- 2. 用API獲取具有特定井號標籤的圖片
- 3. Instagram:在指定的照片後從標籤中獲取照片
- 4. 如何從Instagram獲取具有特殊標籤的圖片?
- 5. 有井號標籤
- 6. 從Instagram獲取照片
- 7. 獲取Instagram標記的用戶照片
- 8. 從文件夾和分頁與PHP獲取所有照片
- 9. 讓所有的井號標籤從用戶
- 10. 如何查看Instagram上有#rainyday標籤的所有9張照片?
- 11. 如何從instagram中獲取標記的照片?
- 12. CertPathValidatorException當試圖從Instagram獲取照片
- 13. 從照片庫使用照片框架獲取所有圖像
- 14. 獲取所有的照片屬於USER_ID
- 15. 獲取來自ALAssetsLibrary的所有照片
- 16. 按標籤Instagram的API搜索顯示的照片,沒有說標籤
- 17. Instagram:通過用戶和標籤獲取照片
- 18. Instagram:通過標籤無限制地獲取照片
- 19. 根據標籤獲取instagram照片/視頻
- 20. Instagram寶石:使用特定#標籤獲取照片
- 21. Instagram的API:是否有可能從某個日期獲得標記的照片?
- 22. Instagram API - 獲取所有用戶媒體
- 23. 獲取具有一對多關係的所有實體,其中一個相關實體符合標準
- 24. 如何從instagram獲取基於用戶和標記的照片
- 25. 獲取所有相冊中的所有照片
- 26. PHP&Xpath:獲取所有第一級HTML標籤(所有兄弟)
- 27. Instagram的API:從也具有一定的主題標籤
- 28. 獲取所有媒體的所有喜歡和評論標籤
- 29. 使用Rails與特定的標籤拉Instagram的照片?
- 30. 所有文字匹配的作用而不是井號標籤
第一個URL似乎中斷了。這一個作品:http://instagram.com/developer/endpoints/tags/ – Shahar
@Shahar更新,謝謝。 –
Instagram的API只是*瘋了*。他們真的希望你獲得每個訪問者的身份驗證只是爲了獲得公共飼料嗎? –