Forrst.com has become a community of over 23000 Developers and Designers in only a few months, and this tutorial will teach you how to use a simple Forrst API call to grab the public data for a forrst user.
As of March 2011 this still works, but may change as their API is still being developed. We will use a simple PHP get file contents call to grab the JSON data, and then convert that into a useful PHP array, which in turn will be used to generate a simple html display.
You can use this to generate your own pages with your Forrst data or perhaps a useful application for Forrst users.
There will be a lot more to come in the full API release, but you’ll have to ask Kyle Bragger about that.
Clicking the above image will take you to a demo using the code explained below.
Active Usernames from Forrst by forsst.com
file_get_contents in PHP by PHP.net
json_decode in PHP by PHP.net
How to get Forrst user data
At this time the Forrst API does not have a search functionality, so this will only work with exact username matches.
For the demo I started it with my own, but you can type in any other valid username and see their info as well.
In order to grab the json data we are using a simple PHP function:
This function uses two built-in php functions “get_file_contents” and “json_decode” to do the hard work for you. The first one grabs the data via the API URL provided by Forrst.
The second converts the returned data into useful PHP arrays. Note: json_decode only work in PHP5.2+ and the module must be installed in apache on your server.
The Data Returned:
The API call returns a block of data, which when converted into arrays contains the following information:
- $user['id'] : The Forrst ID #
- $user['username'] : The Username.
- $user['name'] : The Name.
- $user['url'] : The Profile URL for the User.
- $user['posts'] : The # of Posts Created by the User on Forrst.
- $user['comments'] : The # of Comments made by the User on Forrst Posts.
- $user['likes'] : The # of Likes made by the User on Forrst Posts.
- $user['followers'] : The # of people following this User.
- $user['following'] : The # of people followed by this User.
- $user['photos'] : Array of all the images stored for this user on Forrst.
- [xl_url] (200px by 200px)
- [large_url] (150px by 150px)
- [medium_url] (75px by 75px)
- [small_url] (45px by 45px)
- [thumb_url] (25px by 25px)
- $user['in_directory'] : 1 meaning the user is in the forrst directory and 0 if they are not.
- $user['tag_string'] : comma delimited string of tags the user finds themselves interested in.
At the time of this writing there are additional fields being returned that may later on be used for proper authentication as there is currently no authentication to pull this data.
These fields are:
- $data['stat'] : Returns the status of the response. “ok” if the request succeeded. “fail” in case of an error.
- $data['in'] : Returns the time it took to execute the request in seconds.
- $data['authed'] : Currently returns empty or “false”. This field tells us if the request was authorized.
- $data['authed_as'] : Currently returns empty or “false”. This field will most likely tell us in the future which API user made the request.
- $data['env'] : Currently just returns “prod” (As in Production Environment) This fields is probably more useful to the Forrst Devs than to us.
- In case of failure: $data['error'] : Contains the textual Error Message returned by the API
To display the data in the demo I used some basic html to just output the data to the screen, including basic usage of all the returned user data.
The great thing is that once you have the data array, you can essentially do anything you want with it.
Below follows a display example of the results.
The Forrst API is still in its infancy and at this time you can only do some basic requests, but we know they are working on releasing a full version soon that should have a lot more functionality.
For now, I hope this tutorial just gave you an idea of what sort of data you will be able to expect from the Forrst API, and also showed you how you can use a little bit of code to process and display the data returned by the API.
The full PHP/HTML/CSS source is available here: Here