Skip to content

Instantly share code, notes, and snippets.

@khalib
Last active April 26, 2016 22:47
Show Gist options
  • Select an option

  • Save khalib/b9b49080171c47418a9128857b8da160 to your computer and use it in GitHub Desktop.

Select an option

Save khalib/b9b49080171c47418a9128857b8da160 to your computer and use it in GitHub Desktop.
Get users using the API driver
<?php
function get_users() {
// API object is globally set.
global $api;
// Request #1: returns request object with query defaults (limit: 15, page: 1, fields: <all>, sort: none).
$users = $api
->users()
->get();
// Request #2: returns request object with query attributes set.
$fields = array('id', 'created', 'display_name'); // only returns these fields in each user object
$sort = '-created'; // sorts users in descending order by created date
$limit = 3; // fetches 3 results.
$users = $api
->users()
->fields($fields)
->sort($sort)
->limit($limit)
->get();
}
object(stdClass)#5220 (3) {
["statusCode"]=>
int(200)
["count"]=>
int(83474)
["response"]=>
array(3) {
[0]=>
object(stdClass)#5219 (3) {
["id"]=>
int(2944756)
["display_name"]=>
string(7) "Kari C."
["created"]=>
string(24) "2016-04-21T17:08:54.000Z"
}
[1]=>
object(stdClass)#5221 (3) {
["id"]=>
int(2944736)
["display_name"]=>
string(9) "Lenore b."
["created"]=>
string(24) "2016-04-21T16:56:46.000Z"
}
[2]=>
object(stdClass)#1769 (3) {
["id"]=>
int(2944721)
["display_name"]=>
string(6) "Ms. B."
["created"]=>
string(24) "2016-04-21T16:15:18.000Z"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment