Returns an array of users with standard information and metadata. Also returns userCount - the number of users found in the search.
Name | Type | Required | Default value | Description |
---|
vhost | int | Required | none | The vhost for the request. |
filters | array | Optional | array() | Any search that you wish to perform that would result in a list of users. A list of filters is available below |
offset | int | Optional | 0 | The offset for the result set, i.e. which user to start with (this is normally used with pagination) |
limit | int | Optional | 50 | limits the amount of users to be returned in list |
fields | array | Optional | array() | Specify what userinfo is to be returned. The default array that will be returned for a given search. The complete list is available below. |
sort | string | Optional | 'created desc' | Define how you want the result set to be sorted. Use any of these fields with an 'asc' or 'desc' afterwards: id, user, created, firstname, nickname, lastname, friends, city, country, gender, email, publicfiles, umoderatedfiles, approvedfiles, deniedfiles, active, lastlogin and distance.
NB 1: The distance refers to the distance from the deviceGeoCenter; this can be used to sort the result set only if filters[deviceGeoDistance] and filters[deviceGeoCenter] are provided.
NB 2: The distance can be used to sort the result set only in ascending order, so adding 'desc' after it will not change the order of the results. |
getExternalIds | bool | Optional | false | DEPRECATED: Do not use; intead, set Field 'externalids'. If getExternalIds is set to true, it will return any external id of the the users in the result set. |
includeDeviceInfo | bool | Optional | false | DEPRECATED: Do not use; intead, set Field deviceInfo'. If includeDeviceInfo is set to true, it will return an array of the user's devices in the result set. |
uid | mixed | Optional | 0 | |
followingId | int | Optional | 0 | If set to a userID, it will check if the user who is returned, is being followed or not by the user represented by followingId, will use loggedInUser if session provided |
userId | int | Optional | 0 | Required for imFollowing or followingMe filters to work, otherwise logged in user will be used, and will enforce blocked users |
mediaId | mixed | Optional | 0 | |
includeChildGroups | mixed | Optional | false | |
The filters that are available for use in the getUsers service call.
Name | Type | Description |
---|
firstname | STRING | The first name of users. |
lastname | STRING | The last name of users. |
user | STRING | User's user name. |
city | STRING | User's city. |
country | STRING | User's country. |
active | BOOLEAN | Filters the userlist based on whether or not a user account is active: Set to 'true' to return active accounts only. Set to 'false' to return inactive accounts only. Do not set this filter to return both kinds of user accounts. |
disabled | BOOLEAN | Filters the userlist based on whether or not a user account is disabled: Set to 1 or 'true' to return disabled accounts only. Set to 0 or 'false' to return enabled accounts only. Do not set this filter to return both kinds of user account. |
nid | INT | A particular notification id which had been sent to these users. |
groupid | INT/ARRAY | A particular group id or list of groups which users may be a part of. |
eventid | INT | A particular event id which users may be a part of. |
appcode | STRING | App code identifier |
deviceGeoDistance | INT | Distance in meters from coordinates specified in deviceGeoCenter. |
deviceGeoCenter | coordinates | A center point to be used with deviceGeoDistance in format of lat,long. eg 38.53,77 |
deviceLastUpdateTime | INT or STRING | The timestamp or datetime used to filter users by showing only the users with devices that had their location updated after this date/time. Examples: datetime '2013-04-18 12:41:38' is the same as timestamp 1366288898.
Note: If the deviceLastUpdateTime value is set to epoch ('1970-01-01 00:00:00' or 0) or NULL, then all the users will be returned, not only the ones with devices. |
commentNotification | BOOLEAN | Whether or not a user has mobile comment notifications enabled, 0 is false, 1 is true. |
assignmentNotification | BOOLEAN | Whether or not a user has mobile comment notifications enabled, 0 is false, 1 is true. |
geo | STRING | Set this to 'notnull' to return only the users that have valid geo-location values, meaning ones with geo_latitude <> null and geo_longitude <> null. | empty |
imFollowing | BOOL | Only return users who user follows, uid must be provided | empty |
followingMe | BOOL | Only return users who follow user, uid must be provided | empty |
Below are the fields available in the returned array.
Name | Type | Description |
---|
uid | INT | The users ID if they are not logged in | 0 |
followers | INT | The number of user's following the user. |
following | INT | The number of user's the user follows. |
id | INT | The user id for the requested users. |
user | STRING | The user name for the requested users. |
firstname | STRING | The first name for the requested users. |
lastname | STRING | The last name for the requested users. |
avatar | INT | The media items that the users may be using as their avatar. |
city | STRING | The city in which the requested users live. |
country | STRING | The country in which the requested users live. |
gender | CHAR | The gender of the requested users. M for male and F for female. |
birthdate | DATE | The date of birth for the requested users. |
language | STRING | The user's preferred language. A two character ISO country code will be used. |
email | STRING | The e-mail address of the requested users. |
phone | STRING | The users phone number. |
cellphone | STRING | The user's cell phone number. |
state | STRING | The state in which the requested users live. |
lastlogin | DATETIME | The date and time that the user was last logged into the system. |
geo_latitude | FLOAT | The geographical latitude of the requested users. |
geo_longitude | FLOAT | The geographical longitude of the requested users. |
publicfiles | INT | The total number of media items the user has uploaded to the system. NOTE: You can find the value of notdeniedfiles by subtracting deniedfiles from publicfiles. |
unmoderatedfiles | INT | The number of media items that the user has uploaded to the system that are yet to be moderated. |
approvedfiles | INT | The number of media items the user has uploaded to the system that have been approved. |
deniedfiles | INT | The number of media items the user has uploaded to the system that have been denied. |
unmoderatedcomments | INT | The number of comments the user has posted that have yet to be moderated. |
approvedcomments | INT | The number of comments the user has posted that have been approved. NOTE: You can find the value of notdeniedcomments by calculating the sum of approvedcomments plus unmoderatedcomments. |
deniedcomments | INT | The number of comments the user has posted that have been denied. |
notdeniedcomments | INT | The number of comments the user has posted that have been approved or have yet to be mopderated. |
newsletter | BOOLEAN | Whether or not the user has requested the newsletter, 0 is false, 1 is true. |
deviceinfo | ARRAY | An array of the user's devices. The values returned are as follows: (with i being the iterator of the user's devices, should the user have more than one)
- deviceinfo[i]['id'] - (Integer) The id of the device. ie. 54321
- deviceinfo[i]['uid'] - (Integer) The id of the user.
- deviceinfo[i]['vhost'] - (Integer) The id of the vhost.
- deviceinfo[i]['device_id'] - (String) The string id of the device.
ie: 1f6d530974e0aae8d6ad52734bcead167edab73d40127f8ec762f42d674386fb - deviceinfo[i]['latitude'] - (FLoat) The latitude of the device. Ie: 43.635609
- deviceinfo[i]['longitude'] - (FLoat) The longitude of the device. Ie: -79.424858
- deviceinfo[i]['lastupdatetime'] - (Datetime) The datestamp of the last occurance that the device was used to connect to the application. Ie: 2012-12-07 11:40:56
- deviceinfo[i]['commentnotification'] - (Integer) Indicates whether the user enabled their comment notifications or not. Values: 1 (yes) or 0 (no)
- deviceinfo[i]['assignmentnotification'] - (Integer) Indicates whether the user enabled their assignment notifications or not. Values: 1 (yes) or 0 (no)
- deviceinfo[i]['settings'] - a serialized string with the user's settings: ie: a:1:{s:22:"notificationBadgeCount";s:1:"0";}
- deviceinfo[i]['distance'] - (integer) The distance in meters from the deviceGeoCenter. This is returned only if filters[deviceGeoDistance] and filters[deviceGeoCenter] are provided.
|
externalids | ARRAY | The user's external IDs, if any. |
created | DATETIME | The date and time that the user was created. |
profile_complete | INT | Is the user's profile complete. 1 - yes, 0 - no. |
disable_media_notifications | INT | Has the user disbled their media notifications: 1 - yes, 0 - no. |
disable_thread_notifications | INT | Has the user disbled their thread notifications: 1 - yes, 0 - no. |
occupation | STRING | The user's occupation. |
friends | INT | The number of user's accepted friends. |
followers | INT | The number of user's following the user. |
following | INT | The number of user's the user follows. |
vhost | INT | The application that the user is in. |
meta | ARRAY | The user's meta data. |
active | INT | Indicates whether or not a user account is active: 1 = active, 0 = inactive. |
disabled | INT | Indicates whether or not a user account is disabled: 1 = disabled, 0 = enabled. |
gravatarid | STRING | An md5 hash of the user's email address, which is used to confirm the user's gravatar. |
Below are the fields that you can specify to have returned by this function.
Name | Type | Description |
---|
id | INT | The user id for the requested users. |
user | STRING | The user name for the requested users. |
firstname | STRING | The first name for the requested users. |
lastname | STRING | The last name for the requested users. |
avatar | INT | The media items that the users may be using as their avatar. |
city | STRING | The city in which the requested users live. |
country | STRING | The country in which the requested users live. |
gender | CHAR | The gender of the requested users. M for male and F for female. |
birthdate | DATE | The date of birth for the requested users. |
language | STRING | The user's preferred language. A two character ISO country code will be used. |
email | STRING | The e-mail address of the requested users. |
phone | STRING | The users phone number. |
cellphone | STRING | The user's cell phone number. |
state | STRING | The state in which the requested users live. |
geo_latitude | FLOAT | The geographical latitude of the requested users. |
geo_longitude | FLOAT | The geographical longitude of the requested users. |
publicfiles | INT | The number of media items the user has uploaded to the system. NOTE: You can find the value of notdeniedfiles by subtracting deniedfiles from publicfiles. |
unmoderatedfiles | INT | The number of media items the user has uploaded to the system that have yet to be moderated. |
approvedfiles | INT | The number of media items the user has uploaded to the system that have been approved. |
deniedfiles | INT | The number of media items the user has uploaded to the system that have been denied. |
unmoderatedcomments | INT | The number of comments the user has posted that have yet to be moderated. |
approvedcomments | INT | The number of comments the user has posted that have been approved. NOTE: You can find the value of notdeniedcomments by calculating the sum of approvedcomments plus unmoderatedcomments. |
deniedcomments | INT | The number of comments the user has posted that have been denied. |
notdeniedcomments | INT | The number of comments the user has posted that have been approved or have yet to be mopderated. |
newsletter | BOOLEAN | Whether or not the user has requested the newsletter, 0 is false, 1 is true. |
deviceinfo | ARRAY | An array of the user's devices, returned only when deviceinfo is included in the 'fields' array. The values returned are as follows: (with i being the iterator of the user's devices, should the user have more than one)
- deviceinfo[i]['id'] - (Integer) The id of the device. ie. 54321
- deviceinfo[i]['uid'] - (Integer) The id of the user.
- deviceinfo[i]['vhost'] - (Integer) The id of the vhost.
- deviceinfo[i]['device_id'] - (String) The string id of the device.
ie: 1f6d530974e0aae8d6ad52734bcead137edab73d40127f8ec762f42d674386cb - deviceinfo[i]['latitude'] - (FLoat) The latitude of the device. ie: 43.635609
- deviceinfo[i]['longitude'] - (FLoat) The longitude of the device. ie: -79.424858
- deviceinfo[i]['lastupdatetime'] - (Datetime) The datestamp of the last occurance that the device was used to connect to the application. ie: 2012-12-07 11:40:56
- deviceinfo[i]['commentnotification'] - (Integer) Indicates whether the user enabled their comment notifications or not. Values: 1 (yes) or 0 (no)
- deviceinfo[i]['assignmentnotification'] - (Integer) Indicates whether the user enabled their assignment notifications or not. Values: 1 (yes) or 0 (no)
- deviceinfo[i]['appcode'] - (String) Associates users device with specific mobile app.
- deviceinfo[i]['settings'] - a serialized string with the user's settings: ie: a:1:{s:22:"notificationBadgeCount";s:1:"0";}
- deviceinfo[i]['distance'] - (integer) The distance in meters from the deviceGeoCenter. This is returned only if filters[deviceGeoDistance] and filters[deviceGeoCenter] are provided.
|
externalids | INT | The user's external IDs, if any. |
created | DATETIME | The date and time that the user was created. |
profile_complete | INT | Is the user's profile complete. 1 - yes, 0 - no. |
disable_media_notifications | INT | Has the user disbled their media notifications: 1 - yes, 0 - no. |
disable_thread_notifications | INT | Has the user disbled their thread notifications: 1 - yes, 0 - no. |
occupation | STRING | The user's occupation. |
friends | INT | The number of user's accepted friends. |
vhost | INT | The application that the user is in. |
meta | ARRAY | The user's meta data. |
active | INT | Indicates whether or not a user account is active: 1 = active, 0 = inactive. |
disabled | INT | Indicates whether or not a user account is disabled: 1 = disabled, 0 = enabled. |
gravatarid | STRING | An md5 hash of the user's email address, which is used to confirm the user's gravatar. |
Sample REST Response
http://api.newspark.ca/services/rest/users/getUsers?vhost=[VHOST_ID]&filters[city]=FILTER_CITY&fields[]=firstname&fields[]=lastname&fields[]=email&fields[]=city&sort=created%20DESC&fields[]=externalids&APIKEY=[APIKEY]
<?xml version="1.0" encoding="UTF-8"?>
<result>
<totalCount>2</totalCount>
<data>
<item>
<id>USER_ID</id>
<firstname>USER_FIRSTNAME</firstname>
<lastname>USER_LASTNAME</lastname>
<city>Toronto</city>
<country>CA</country>
<avatar>0</avatar>
<email>USER_EMAIL_ADDRESS</email>
<user>USERNAME</user>
<gender>M</gender>
<offset>0</offset>
</item>
<item>
<id>USER_ID</id>
<firstname>USER_FIRSTNAME</firstname>
<lastname>USER_LASTNAME</lastname>
<city>toronto</city>
<country>CA</country>
<avatar>0</avatar>
<email>USER_EMAIL</email>
<user>USERNAME</user>
<gender>M</gender>
<offset>1</offset>
</item>
</data>
</result>
Sample JSON Response
{
"status": true,
"result": {
"id": USER_ID,
"user": "USER_NAME",
"password": "HASHED_USER_PASSWORD",
"email": "USER_EMAIL",
"firstname": "USER_FIRSTNAME",
"lastname": "USER_LASTNAME",
"city": "Toronto",
"gender": "M",
"birthdate": "2011-02-01",
"cellphone": "4162222222",
"phone": "4162222222",
"website": "",
"occupation": "",
"address1": "1 Toronto Road",
"address2": null,
"postalcode": "M1M1M1",
"state": "ON",
"language": "",
"country": "CA",
"description": "",
"storage": 0,
"avatar": 0,
"created": "2012-02-03 14:48:50",
"lastlogin": "2012-02-03 16:30:11",
"random1": 5045,
"random2": 151285996,
"accounttype": 0,
"active": "1",
"disabled": "0",
"newsletter": "0",
"openidurl": "",
"nickname": "",
"attempts": 0,
"mobileblog": 0,
"publicfiles": 0,
"unmoderatedfiles": 0,
"approvedfiles": 0,
"deniedfiles": 0,
"friends": 1,
"friends_notconfirmed": 0,
"geo_latitude": "41.83209336689739",
"geo_longitude": "-84.44921875",
"vhost": 231,
"meta": {
"lang": "en",
"twitterUserName": "",
"rules": "1"
},
"no_comment_notifications": 0,
"profile_complete": 1,
"externalids": {},
"deviceInfo":
"0": {
"id" : DEVICE_ID,
"uid" : USER_ID,
"vhost" : 239,
"device_id" : "04dbc117fbe284db71d3be1f37fe2e00fa13176da87f4e66de376606fdf05558",
"latitude" : "43.635872",
"longitude" : "-79.424721",
"lastupdatetime" : "2012-11-23 12:33:19",
"commentnotification" : 0,
"assignmentnotification" : 0,
"settings] : "a:1:{s:22:"notificationBadgeCount";s:1:"0";}"
},
"1": {
"id" : DEVICE_ID,
"uid" : USER_ID,
"vhost" : 239,
"device_id" : "14dbc117fbe284db71d3be1f37fe2e00fa13176da87f4e66de376606fdf05558",
"latitude" : "45.635872",
"longitude" : "-78.424721",
"lastupdatetime" : "2012-11-24 12:33:19",
"commentnotification" : 0,
"assignmentnotification" : 0,
"settings] : "a:1:{s:22:"notificationBadgeCount";s:1:"0";}"
}
}
}
PHP-RPC
$path = 'https://api.newspark.ca/services/php';
// Listing the arguments
$arguments = array(
'APIKEY' => 'YOURAPIKEY',
'method' => 'users.getUsers',
'vhost' => '2',
'filters' => $filters,
'offset' => $offset,
'limit' => $limit,
'fields' => $fields,
'sort' => $sort,
'getExternalIds' => $getExternalIds,
'includeDeviceInfo' => $includeDeviceInfo,
'uid' => $uid,
'followingId' => $followingId,
'userId' => $userId,
'mediaId' => $mediaId,
'includeChildGroups' => $includeChildGroups
);
// http_build_query basically turns an array into a url-encoded list of variables
$url = $path .'?' . http_build_query($arguments,null,'&');
// get the contents from the specified url
$data = file_get_contents($url);
// transform it back into php data structures
$data = unserialize($data);
// the actual data is stored in $data['result']
print_r($data['result']);
back to topPEAR XMLRPC client
// Include the client
require_once 'XML/RPC.php';
// Create the XMLRPC Client
$client = new XML_RPC_Client('/services/xmlrpc?APIKEY={YOURAPIKEY}', 'api.newspark.ca');
// PEAR's XML-RPC client requires all arguments to wrapped in a special value class
// XML_RPC_encode converts this automatically
$arguments = array(
XML_RPC_encode('2'),
XML_RPC_encode($filters),
XML_RPC_encode($offset),
XML_RPC_encode($limit),
XML_RPC_encode($fields),
XML_RPC_encode($sort),
XML_RPC_encode($getExternalIds),
XML_RPC_encode($includeDeviceInfo),
XML_RPC_encode($uid),
XML_RPC_encode($followingId),
XML_RPC_encode($userId),
XML_RPC_encode($mediaId),
XML_RPC_encode($includeChildGroups)
);
// Creating an XML-RPC message
$message = new XML_RPC_Message('users.getUsers',$arguments);
// Sending the message to the server
$response = $client->send($message);
// We also need to decode the response back to normal PHP types
$response = XML_RPC_decode($response);
print_r($response);
back to topSabreTooth XMLRPC client
// Include the client
require_once 'Sabre/XMLRPC/Client.php';
// Create the XMLRPC Client
$xmlrpc = new Sabre_XMLRPC_Client('https://api.newspark.ca/services/xmlrpc?APIKEY={YOURAPIKEY}');
$arguments = array(
'2',
$filters,
$offset,
$limit,
$fields,
$sort,
$getExternalIds,
$includeDeviceInfo,
$uid,
$followingId,
$userId,
$mediaId,
$includeChildGroups
);
$data = $xmlrpc->invoke('users.getUsers',$arguments);
print_r($data);
back to topZend XMLRPC client
// Include the client
require_once 'Zend/XmlRpc/Client.php';
// Create the XMLRPC Client
$client = new Zend_XmlRpc_Client('https://api.newspark.ca/services/xmlrpc?APIKEY={YOURAPIKEY}');
$arguments = array(
'2',
$filters,
$offset,
$limit,
$fields,
$sort,
$getExternalIds,
$includeDeviceInfo,
$uid,
$followingId,
$userId,
$mediaId,
$includeChildGroups
);
$data = $client->call('users.getUsers',$arguments);
print_r($data);
back to topActionscript 2
/*
* In ActionScript 2 remote service calls are done using the RemotingConnector Component.
* An instance of the component must exist on the stage and have an instance name.
*
* Results and Faults are handled by addEventListener's and the call parameters are placed inside of an associative array
*
* You must also specify the service class and method names under the appropriate property fields of the component
*/
var gatewayURL:String = "/services/amf2";
//Set up service call
myRemConn_rc.gatewayUrl = gatewayURL;
myRemConn_rc.serviceName = "users";
myRemConn_rc.methodName = "getUsers";
myRemConn_rc.params = {2:vhost, filters:filters, offset:offset, limit:limit, fields:fields, sort:sort, getExternalIds:getExternalIds, includeDeviceInfo:includeDeviceInfo, uid:uid, followingId:followingId, userId:userId, mediaId:mediaId, includeChildGroups:includeChildGroups};
myRemConn_rc.addEventListener("result", widgetResult);
myRemConn_rc.addEventListener("status", widgetFault);
//Make the call
myRemConn_rc.trigger();
/*
* Handles service result.
*/
function widgetResult(ev:Object){
//Do stuff
//Data is returned inside of ev.target.results
//(i.e. ev.traget.results.description or ev.traget.results.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object){
//Display Error
trace("Categories Error - " + ev.code + " - " + ev.data.faultstring);
}
back to topActionscript 3
/*
* In ActionScript 3 remote service calls are done using the NetConnection Object.
* A Responder Object controls what functions handle successful or failed calls
* and any parameters for the call are placed in an array and passed as a parameter
* in the NetConnection.call() method.
*/
var gatewayURL:String = "/services/amf2";
var parameters:Array = new Array(vhost, filters, offset, limit, fields, sort, getExternalIds, includeDeviceInfo, uid, followingId, userId, mediaId, includeChildGroups);
var connection:NetConnection = new NetConnection();
connection.connect(gatewayURL);
connection.call("users.getUsers", new Responder(widgetResult, widgetFault), parameters);
/*
* Handles service result.
*/
function widgetResult(ev:Object):void{
//Do stuff
//Data is returned inside of ev
//(i.e. ev.description or ev.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object):void{
//Display Error
error.showError(parentClip, ev.code + " - " + ev.description, "Please refresh your browser to try again.");
error.x = (parentClip.width - error.width) / 2;
error.y = (parentClip.height - error.height) / 2;
}
back to topREST service example
<%@ Page Language="vb" %>
<%
' REST gateway
dim gateway as string = "http://api.newspark.ca/services/rest/"
' Service + method we're calling.
dim method as string = "users/getUsers"
dim apiKey as string = "YOURAPIKEY"
dim url as string = gateway & method & "?APIKEY=" & apiKey & "&vhost=2"
' HTTP Client
dim wcHTTPScrape as new System.net.WebClient()
' Opening a stream
dim objInput as System.IO.Stream = wcHTTPScrape.OpenRead(url)
dim objReader as new System.IO.StreamReader ( objInput )
' Reading the entire HTTP response and output it
Response.Write ( objReader.ReadToEnd () )
objReader.Close ()
objInput.Close ()
%>
back to topjQuery JSON
/*
* jQuery post example
*/
function getUsers ( filters, offset, limit, fields, sort, getExternalIds, includeDeviceInfo, uid, followingId, userId, mediaId, includeChildGroups ) {
var params = {
"method" : 'users.getUsers',
"vhost" : 2,
"filters" : filters,
"offset" : offset,
"limit" : limit,
"fields" : fields,
"sort" : sort,
"getExternalIds" : getExternalIds,
"includeDeviceInfo" : includeDeviceInfo,
"uid" : uid,
"followingId" : followingId,
"userId" : userId,
"mediaId" : mediaId,
"includeChildGroups" : includeChildGroups}
$.post('/services/json',params
,function(response){
console.log(response);
});
back to topLocal API
// Get the Service Mapper
$mapper = Sabre_ServiceMap_Mapper::getMapper();
// Calling the method
$data = $mapper->users->getUsers( 2, $filters, $offset, $limit, $fields, $sort, $getExternalIds, $includeDeviceInfo, $uid, $followingId, $userId, $mediaId, $includeChildGroups );
print_r($data);
back to top