[英]Instagram Basic Display API: how can I limit the number of posts to less than 20?
使用Instagram Basic Display API
,如何將其獲取的帖子數量限制在 20 以下?
在PHP
一個類中,我為端點定義了以下基本URL
:
private $_apiBaseUrl = 'https://api.instagram.com/';
private $_graphBaseUrl = 'https://graph.instagram.com/';
public $userId = ''; // defined here, fetched later by getUser();
這兩個函數獲取帖子:
// get the posts
public function getUsersMedia() {
$params = array(
'endpoint_url' => $this->_graphBaseUrl . $this->userId . '/media',
'type' => 'GET',
'url_params' => array(
'fields' => 'id,caption,media_type,media_url',
)
);
$response = $this->_makeApiCall( $params );
return $response;
}
// get more info on a specific post
public function getMedia( $mediaId ) {
$params = array(
'endpoint_url' => $this->_graphBaseUrl . $mediaId,
'type' => 'GET',
'url_params' => array(
'fields' => 'id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username'
)
);
$response = $this->_makeApiCall( $params );
return $response;
}
在這篇文章中,我找到了這個端點:
https://graph.instagram.com/{user-id}/media?fields={media-fields-you-want-to-return}&access_token={access-token}&limit={number-of-media-you-want-to-return}
但是我將如何使用我的函數來完成這項工作? 我不想使用分頁,但只返回例如最后 5-10 個帖子。
將limit
參數的條目添加到url_params
數組:
'url_params' => array(
'fields' => 'id,caption,media_type,media_url',
'limit' => 5,
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.