Developer / Documentation / OpenSocial REST API
The OpenSocial REST API allows a developer to retrieve pieces of information about a user and his friends by sending HTTP GET requests to our server.
In the other direction, you can also POST two types of messages back to Netlog:
-
Activities about the user that will show up in the logs of his friends:
"Tom just received a gift from Bill!" -
Notifications to the user notifying him of certain events within the application:
"You just received a gift from Bill!"
First of all, you need to make yourself known to our REST server so it knows you and your relation to the people you want to retrieve information from.
Inside the gadget, you can retrieve the token by doing the following in javascript:
var token = shindig.auth.getSecurityToken();Once you get the security-token, you can proceed on doing your requests.
An example of an URL fetching the friends of a specific user:
http://nl.api.netlog.com/opensocial/social/rest/people/31576831/@friends?st=NTVkYmIxYWI4NDcyYWZjMDJjMWI2NmY4MTEwMzE0OWU=
The default output format is JSON. However, if you specify format= in your query, the output will be returned in the desired format.
Our REST API is capable of returning the data in 3 kinds of formats:
- XML
- JSON
- ATOM
For a detailed explanation of what is possible, also see the openSocial RESTful protocol spec.
Some possible actions
| Type | URI | Description |
|---|---|---|
| People: fetching information (GET request) | ||
|
Only publicly available info about a person will be returned. To request specific fields other then the defaults of nickname, age, gender, etc... attach a fields=[comma-separated fields] parameter to the URL. |
|
| People: posting actions (POST request) | ||
| We do not allow people-related actions (e.g. friendship request/remove ...) trough openSocial. | ||
| Fetching activities (GET request) | ||
|
|
|
| Posting activities and notifications (POST request) | ||
| We do not allow sending private messages or e-mails trough openSocial | ||
|
|
|
|
The message should be sent as a json-encoded array in the POST body, as follows: Activity: { "body ": "My activity body text ", "title ": " just posted an activity! "} Notification: { "type " : "notification ", "title " : "requiredButWontShow ", "body " : "myNotifText ", "recipients " : [id1,id2...]} |
||
| Retrieving appdata (GET request) | ||
|
|
|
| Note: you can request the value for oen or more specific keys by passing parameter 'fields' as follows: fields=key1,key2 | ||
| Storing/updatig appdata (POST request) | ||
|
|
|
| Note that app data should be sent as a JSON string in the POST body containing the key-value pair(s) you want to insert or update: { "myKey1" : "myValue1 ", "myKey2 " : "myValue2 "} | ||
Possible query parameters when fetching data
(whenever relevant)| Parameter | Description |
|---|---|
| count={value} |
If you specify this parameter, our container will only return the x amount of results you want. If a request ends up generating 30 results, and you only want to retrieve 10 of them, use this parameter. |
| filterBy={value} | Returns items from a collection, filtered by the given field. We currently only support topFriends. |
| filterOp={value} | The operation to use when filtering a collection. At this time we only support "contains" |
| filterValue={value} | The value to use when filtering a collection. |
| format={value} | Format desired. Pick between ATOM, JSON or XML. Default is JSON if not provided. |
| fields={value} | List of the fields you want to include in the resultset. If no fields are provided, we will return the userid and profileUrl. If you want to specify multiple fields, please a comma as delimiter.
http://nl.api.netlog.com/opensocial/social/rest/people/ |
| sortBy={value} | For a collection, return entries sorted by the given field. Currently we only support sorting by displayName and topFriends. |
| sortOrder={value} | Can either be "ascending" or "descending", defaults to ascending. Used to sort objects in a collection. |
| startIndex={value} | Starts displaying the results starting from startIndex. For example, if the request returns 30 items, but you only want the last 10, you would specify a startIndex of 20. |
Some examples
Fetch information about myself (GET).
http://nl.api.netlog.com/opensocial/social/rest/people/@me/@self?st=OTI3MTM3ODdjNTgwMjJlOGE0MGFiZDc4OTllMzM3MzI=&fields=id,status,thumbnailUrl
Will fetch info about the requester (the logged in user).
Will only return the fields id, status and thumbnailUrl.
http://nl.api.netlog.com/opensocial/social/rest/people/@me/@friends?st=OTI3MTM3ODdjNTgwMjJlOGE0MGFiZDc4OTllMzM3MzI=&fields=profileUrl,displayName
Will fetch info about the friends of the requester (the logged in user).
Will only return the fields profileUrl and displayName.
http://nl.api.netlog.com/opensocial/social/rest/activities/57854631/@self?st=NTQyZWY0NDAyNGE2OTQ4ZDc5NWUwY2I1OWM5NzAwZDg=
Will return all the activities (20 items per page default) for the given user (user with userId 57854631 in this example).
Post an activity for a user (POST).
http://nl.api.netlog.com/opensocial/social/rest/activities/57854631/@self?st=NTQyZWY0NDAyNGE2OTQ4ZDc5NWUwY2I1OWM5NzAwZDg=
POSTbody: { "title" : "sneezed!", "body" : "Bless him."}
Will post an activity log to all friends of the given user (about user with userId 57854631 and text 'UserName sneezed!' in this example).
Post a notification for a user (POST).
http://nl.api.netlog.com/opensocial/social/rest/messages/57854631/@self?st=NTQyZWY0NDAyNGE2OTQ4ZDc5NWUwY2I1OWM5NzAwZDg=
POSTbody: {"type" : "notification", "title" : "requiredButWontShow", "body" : "hi!", "recipients" : [57854631]}
Will post a clickable notification to the given user (with userId 57854631 and text 'hi!' in this example).
Should you require more information about REST in OpenSocial, please visit the official REST documentation
Articles for app developers
Must-reads: Tutorials: creating apps with JS and PHP- Tutorial 1: OpenSocial JS API
- Tutorial 2: OpenSocial REST API
- Tutorial 3: OpenSocial example app
- Tutorial 4: OpenSocial PHP client
- Tutorial 5: Flash and OpenSocial
- Deprecated: Netlog REST API Flash Applications PHP Applications
Vänligen vänta...