我試圖修復阿賈克斯Instagram的API分頁阿賈克斯Instagram的API分頁試圖修復錯誤
只顯示20張照片。 「加載更多」按鈕不起作用。
在控制檯:
Uncaught ReferenceError: maxid is not defined
這裏是index.php文件:
<script>
$(document).ready(function() {
$('#more').click(function() {
var max_id = $(this).data('nextid');
$.ajax({
type: 'GET',
url: 'ajax.php',
data: {
max_id: maxid
},
dataType: 'json',
cache: false,
success: function(data) {
// Output data
$.each(data.images, function(i, src) {
$('#photos').append('<li><img src="' + src + '"></li>');
});
// Store new maxid
$('#more').data('maxid', data.next_id);
}
});
});
});
</script>
<?php
require_once 'instagram.class.php';
$instagram = new Instagram(array(
'apiKey' => '*****',
'apiSecret' => '*****',
'apiCallback' => '******'
));
// Receive OAuth code parameter
$code = $_GET['code'];
if (true === isset($code)) {
$data = $instagram->getOAuthToken($code);
$instagram->setAccessToken($data);
$media = $instagram->getUserMedia();
}
?>
<ul id="photos">
<?php foreach($media->data as $data): ?>
<li><img src="<?php echo $data->images->thumbnail->url ?>"></li>
<?php endforeach; ?>
<?php echo "<br><button id=\"more\" data-maxid=\"{$media->pagination->next_max_id}\">Load more ...</button>"; ?>
ajax.php:
require_once 'instagram.class.php';
$instagram = new Instagram(array(
'apiKey' => '****',
'apiSecret' => '*****',
'apiCallback' => '*******'
));
// Receive OAuth code parameter
$code = $_GET['code'];
if (true === isset($code)) {
$data = $instagram->getOAuthToken($code);
// Initialize class for public requests
$instagram->setAccessToken($data);
$media = $instagram->getUserMedia();
// Receive AJAX request and create call object
$maxID = $_GET['next_max_id'];
$clientID = $instagram->getApiKey();
$call = new stdClass;
$call->pagination->next_max_id = $maxID;
$call->pagination->next_url = "https://api.instagram.com/v1/users/self/media/recent?client_id={$clientID}&max_id={$maxID}";
// Receive new data
$media = $instagram->pagination($call);
// 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,
'max_id' => $media->pagination->max_id,
'images' => $images
));
我使用https://github.com/cosenary/Instagram-PHP-API
謝謝!
Uncaught ReferenceError: maxid is not defined
maxid
沒有在你的代碼中定義:
**此錯誤在索引點擊「裝載更多」按鈕時。php:** >未捕獲ReferenceError:未定義maxid 那麼我需要把** maxid **而不是? 有max_id和next_max_id從性反應: { 「分頁」:{ 「next_url」:「https://api.instagram.com/v1/users/********/media/ ?最近=的access_token&33174964.1fb234f.707411a10e624f13b6b08dd806df1eab = max_id 278169081097328255_33174964" , 「next_max_id」: 「278169081097328255_33174964」 }, – nuttelko