Instagram Basic Display API:如何将帖子数量限制在 20 个以内?
Instagram Basic Display API: how can I limit the number of posts to less than 20?
如何使用 Instagram Basic Display API
,将其获取的 post 的数量限制在 20 个以内?
在 PHP
中的 class 中,我为端点定义了以下基础 URL
:
private $_apiBaseUrl = 'https://api.instagram.com/';
private $_graphBaseUrl = 'https://graph.instagram.com/';
public $userId = ''; // defined here, fetched later by getUser();
这两个函数得到posts:
// 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;
}
在 post 我找到了这个端点:
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}
但是我该如何使用我的函数来实现它呢?
我不想使用分页,但只使用 return 比如最后 5-10 posts.
将 limit
参数的条目添加到 url_params
数组:
'url_params' => array(
'fields' => 'id,caption,media_type,media_url',
'limit' => 5,
)
如何使用 Instagram Basic Display API
,将其获取的 post 的数量限制在 20 个以内?
在 PHP
中的 class 中,我为端点定义了以下基础 URL
:
private $_apiBaseUrl = 'https://api.instagram.com/';
private $_graphBaseUrl = 'https://graph.instagram.com/';
public $userId = ''; // defined here, fetched later by getUser();
这两个函数得到posts:
// 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}
但是我该如何使用我的函数来实现它呢? 我不想使用分页,但只使用 return 比如最后 5-10 posts.
将 limit
参数的条目添加到 url_params
数组:
'url_params' => array(
'fields' => 'id,caption,media_type,media_url',
'limit' => 5,
)