Api for android app based on ask.fm
Various conventions related to the API are documented here.
URL Construction
{base_url} and {version_number} are two placeholders that will be used all over this document. There values are defined below.
- {base_url} : http://127.0.0.1/ (base url of the main API)
- {version_number} : v1 (the current version of the API)
Values of these two will be used to generate the URLs for every API request.
{base_url}/{version_number}/login
eg. http://example.com/v1/login
eg. http://example.com/v1/feeds
eg. http://example.com/v1/trending
POST Parameters
All POST requests need to provided with parameters as form values. [1] (Content-Type: application/x-www-form-urlencoded)
GET Parameters
All the GET endpoints of the API need to be supplied with parameters in the form of the standard [query string][2].
Response
The response returned by all the endpoints will be in JSON. ("Content-Type": "application/json")
Basic HTTP authentication will be used for authentication right now which basically requires every request to the server to have a set of credentials as the value of the "Authorization" key.
Structure of Header Field
Authentication: Basic username:password
The header field is consisting of 3 different parts. All of them are explained below.
- Authentication - Name of the header field.
- Basic - Type of authentication. (Basic HTTP Authentication in our case)
- username:password - Combination of username and password seperated by a ":". The "username" will the FB User ID and "password" the FB access token in our case.
The error codes raised by every endpoint are documented in the respective sections itself. Here the different keys which a response will have in the case of an error are explained.
{
"error": true,
"error_code": 1221,
"error_message": "Facebook access token provided is invaid."
}
- **error(boolean):**Flag signfying if the request resulted in an error not. The android app can continue with normal workflow if the value of this key is "false" but would have to take error handling measures if the value is "true".
- **error_code (integer):**Error code. (the various error codes raised by every endpoint are explained in the respective sections of the endpoints.
- **error_message (string):**Human readable error message.
Various endpoints with the HTTP verb they support are explained in this section
- Registers a new user if the user does not already exists.
- Returns a simple success flag back if the user already exists.
- fb_user_id (string): - Facebook User ID.
- fb_access_token (string): - Facebook Access Token
{
"error": false,
"success": true,
"new_registration": false,
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **success (boolean):**Simple flag telling if the request was a success or not. (Frankly there is not practical purpose of this one with the existence of the error flag.)
- **new_registration (boolean):**Flag telling if the current request resulted in a new user registration or the given user already existed in the system.
- **1221:**When the access token provided is not valid.
- **1222:**When the access token provided is valid but does not match with the given user ID.
- 500:: Internal server error.
- Returns random questions answered by the users friends
- fb_user_id (string) : - Facebook User Id
- fb_access_token (string) : - Facebook Access Token
- skip (integar) : - Starting point for the feed to be sent
- limit (integer) : - Number of Feeds to be sent
{
"error": false,
"skip": 100,
"limit": 50,
"count": 50,
"results": [
{
"asker_name": Alex Josh,
"asker_pic": pic_url,
"asker_id": askers_user_id(in system),
"question_content": question asked to the user?? ,
"answer_content": answer given to that question,
"time": answer time,
"score": like count,
"replier_pic": pic_url,
"replier_name": John Doe,
"replier_id": replier_user_id,
},{...},{...}]
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **skip (integer):**Value of the skip parameter provided.
- **limit (integer):**Value of the limit parameter provided.
- **result (array):**Array of feeds to be shown to the user.
- **asker_name (string):**Name of the person who asked the question.
- **asker_pic (string):**Url of the picture of the asker.
- **asker_id (string):**Id of the asker.
- **question_content (string):**question asked to the user.
- answer_content (string) : answer given to that question.
- **time (string):**answer time.
- **score (integer):**like count.
- **replier_pic (string):**Url of the picture answered the question.
- replier_name (string): Name of the replier.
- **replier_id (string):**Id of the replier.
- **count (integer):**The number of feeds in result
- A similar response to that of feed will be generated except that the result will contain the questions and answers belonging to any random people not followed by or following the logged in user.
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- skip (integar) : - Starting point for the response to be sent.
- limit (integer) : - Number of responses to be sent.
{
"error": false,
"skip": 100,
"limit": 50
"count": 50,
"result": [
{
"user_id": id_string,
"user_name": Alex Josh
"user_pic": pic_url,
"ans_count": 100,
"likes_count": 455,
"followers_count": 160,
},{...},{...},]
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **skip (integer):**Value of the skip parameter provided.
- **limit (integer):**Value of the limit parameter provided.
- **result (array):**Array of feeds to be shown to the user.
- **user_id (string):**Id of the user.
- **user_name (string):**Name of the user.
- **user_pic (string):**Url of the picture of the user.
- **ans_count (integer):**Number of answers given by the user.
- **likes_count (interger):**Total number of likes on all answers given by the user.
- **followers_count (integer):**Total number of people followning the user.
- **count (integer):**The number of feeds in result
- Returns the bio of the user that the logged-in user wants to see.
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- other_user_id (string) : - User Id of the other user whose profile has to be seen.
{
"error": false,
"user_id": Id_string,
"user_name": Alex Josh,
"user_pic": pic_url,
"ans_count": 2345,
"likes_count": 43435,
"followers_count": 2133,
"count": 50,
"answers": [
{
"asker_name": Alex Josh,
"asker_pic": pic_url,
"asker_id": askers_user_id(in system),
"question_content": question asked to the user?? ,
"answer_content": answer given to that question,
"time": answer time,
"score": like count,
"replier_pic": pic_url,
"replier_name": John Doe,
"replier_id": replier_user_id,
},{...},{...}]
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **user_id (string):**Id of the user.
- **user_name (string):**Name of the user.
- **user_pic (string):**Url of the picture of the user.
- **ans_count (integer):**Number of answers given by the user.
- **likes_count (interger):**Total number of likes on all answers given by the user.
- **followers_count (integer):**Total number of people followning the user.
- **answers (array):**This array will contain the answers given by the user visited.
- **count (integer):**The number of feeds in result
- /followers - Returns the list of people following the logged-in user
- /following - Returns the list of people being followed by the logged-in user
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- skip (integar) : - Starting point for the response to be sent.
- limit (integer) : - Number of responses to be sent.
{
"error": false,
"skip": 100,
"limit": 50,
"count": 50,
"result": [
{
"user_id": id_string,
"user_name": Alex Josh
"user_pic": pic_url,
"ans_count": 100,
"likes_count": 455,
"followers_count": 160,
},{...},{...},]
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **skip (integer):**Value of the skip parameter provided.
- **limit (integer):**Value of the limit parameter provided.
- **result (array):**Array of feeds to be shown to the user.
- **user_id (string):**Id of the user.
- **user_name (string):**Name of the user.
- **user_pic (string):**Url of the picture of the user.
- **ans_count (integer):**Number of answers given by the user.
- **likes_count (interger):**Total number of likes on all answers given by the user.
- **followers_count (integer):**Total number of people followning the user.
- **count (integer):**The number of feeds in result
- Returns the list of questions asked to the logged-in user.
- Also shows the system generated questions that he can answer.
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- skip (integar) : - Starting point for the response to be sent.
- limit (integer) : - Number of responses to be sent.
{
"error": false,
"skip": 100,
"limit": 50,
"count": 50,
"questions": [
{
"question_id": Id_string,
"question_content": question asked to the logged-in user,
"question_time": 23:00 4,23,2013,
"asker_id": Id_string
"asker_name": Alex Josh,
"asker_pic": pic_url,
},{...},{...},]
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **skip (integer):**Value of the skip parameter provided.
- **limit (integer):**Value of the limit parameter provided.
- **result (array):**Array of feeds to be shown to the user.
- **count (integer):**The number of feeds in result.
- **questions (array):**Array of questions asked to the logged-in user.
- **question_id (string):**Id of the question asked
- **question_content (string):**Question asked to the logged-in user.
- **question_time (string):**Time when the question is asked.
- **asker_id (string):**Id of the person who asked the question.
- **asker_name (string):**Name of the asker.
- **asker_pic (string):**URL of the picture of the asker.
- Returns a question generated by the system to the user.
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
{
"error": false,
"question_id": Id_string,
"question_content": question asked to the logged-in user,
"question_time": 23:00 4,23,2013,
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **question_id (string):**Id of the question asked
- **question_content (string):**Question asked to the logged-in user.
- **question_time (string):**Time when the question is asked.
- Used to ask a new question to a user.
- Returns the question id if successfully posted.
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- other_user_id (string) : - User Id of the person to whom the question is asked.
- anounimity (boolean) : - To ask the question anonymously or not.
{
"error": false,
"question_id": Id_string,
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **question_id (string):**Id of the question asked.
- Used to post an answer to a question asked by teh user.
- Return Answer_id if successfully posted
- fb_user_id (string) : - Facebook User Id.
- fb_access_token (string) : - Facebook Access Token.
- **question_id (string):**Id of the question asked.
- **answer_content (string):**Content of the answer given.
{
"error": false,
"answer:id": Id_string,
}
- **error (boolean):**Flag indicating if the request resulted in an error or not. If the value is 'true' the response will also have other keys explained in the errors section.
- **question_id (string):**Id of the answer.