I have written a code in PHP to query the search catalog in Mendeley
and retrieve data for a specific journal. However, the problem is that the results are limited until 100. The code is below and is written in PHP. How can I add mendeley
pagination after 100 results?
function auth(){
$client_id = '';
$client_secret = '';
$redirect_uri = '';
if(isset($_GET['code'])) {
if(!isset($_SESSION['access_token'])) {
# Authorize
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.mendeley.com/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded;"));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('client_id'=>$client_id, 'client_secret'=>$client_secret, 'code'=>$_GET['code'],'redirect_uri'=>$redirect_uri, 'grant_type'=>'authorization_code')));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//curl_setopt ($ch, CURLOPT_CAINFO, getcwd()."\cacert.pem");
$server_output = curl_exec ($ch);
$errmsg = curl_error($ch) ;
if($errmsg) {
var_dump($errmsg);
}
curl_close ($ch);
$result = json_decode($server_output, true);
// var_dump($result);
$_SESSION['access_token'] = $result['access_token'];
}
# Call the main function
main();
}
function getResponse($path) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.mendeley.com/".$path);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$_SESSION['access_token'],
'Accept: application/vnd.mendeley-document.1+json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
//curl_setopt ($ch, CURLOPT_CAINFO, getcwd()."\cacert.pem");
$server_output = curl_exec ($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($server_output, 0, $header_len);
$body = substr($server_output, $header_len);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errmsg = curl_error($ch) ;
if($errmsg){
var_dump($errmsg);
}
curl_close ($ch);
return json_decode($server_output, true);
}
function main(){
$search_terms = 'Academy of Management Journal';
$min_year='2012';
$max_year='2016';
$result = getResponse('/search/catalog?source='.urlencode($search_terms).'&min_year='.$min_year.'&max_year='.$max_year.'&limit=2' . '&view=stats' );
var_dump($result);
if(isset($result)) {
if(isset($res['id'])) {
$data[] = getResponse('/catalog/'.$res['id']);
var_dump($data);
sleep(2);
}
}
According to Mendeley Pagination documentation the pagination URL can be obtained from the
Link
field of the HTTP response headerI will use curl as a prototyping tool to illustrate the usage of Mendeley Pagination.
In your example running
Produces the following headers
So the next page can be resolved using URL