Introduction
LittlePolls has launched an API to create polls. Developers are now invited to
use this API to create polls from their applications. Optionally, we also allow
developers to post the polls on selective social networks using our API.
We currently support posting polls to twitter.
Back To Top
Create Poll
Creating a poll on using our API, is as simple as sending a XML Request,
and receiving a XML Response.
We have also provided a sample PHP Client class, which takes cares of the XML
Request, and Response Handling.
XML Request
Here is an example Request XML, followed by an explanation of the elements.
Note: You can specify upto 4 questions in one poll, and upto 4 answers per
question.
Sample XML Request
<?xml version="1.0" encoding="UTF-8" ?>
<request type="createpoll">
<response responsetype="xml" level="advanced" />
<server domain="mydomain.com" user="MY_USERID"
apikey="abcdefghabcdefghabcdefghabcdefgh"/>
<poston server="twitter" user="twitteruser"
passkey="twitterpass" message="Please Vote - {{question}} -
{{url}}" />
<poll myid="MY_POLLID" validity="14" <a
href="#styles">style</a>="0"
access="public">
<question>
<q>Which is the best soft drink in the world?</q>
<a>Coca-Cola</a>
<a>Pepsi</a>
<a>Mirinda</a>
<a>Mountain Dew</a>
</question>
<question>
<q>Which is the best social network?</q>
<a>Facebook</a>
<a>MySpace</a>
<a>Orkut - Google Rocks!!!</a>
<a>Twitter</a>
</question>
<question>
<q>Which movie are we going to watch this saturday?</q>
<a>The Hulk</a>
<a>Iron Man</a>
<a>Batman</a>
<a>Slumdog Millionaire</a>
</question>
<question>
<q>Can I have only two options to a question?</q>
<a>Yes</a>
<a>No</a>
</question>
</poll>
</request>
Explanation of XML Elements
| Element / Attribute |
Required |
Explanation |
Permissible Values |
Default Value |
| response |
no |
Specify what type of response you want from the API |
| responsetype |
no |
Format of the response from the API |
xml |
xml |
| level |
no |
detail level of response See how sample responses differ with level |
url simple advanced |
advanced |
| server |
no |
Identify your server, and userID of end-user (if any).
We will remember poll history for a user by this
combination. |
| domain |
no |
Your domain name. |
Max 32 characters |
|
| user |
no |
userID of end-user on your server. |
Max 32 characters |
|
| apikey |
no |
API KEY issued to you from littlepolls.com. |
Max 32 characters |
|
| poston |
no |
Social Network to post the poll on. |
| server |
no |
Social Network Identifier. |
twitter |
|
| user |
no |
userid on the social network to post the poll. (twitter
username) |
| passkey |
no |
passkey required for the social network to post the poll.
(twitter password) |
| message |
no |
message to be posted. Can specify placeholders like
{{user}}, {{question}} and {{url}} |
|
Please Vote - {{question}} - {{url}} |
| poll |
yes |
Poll Details (Contains 1-4 questions) |
| myid |
no |
A Poll ID of your choice that you want to associate with the poll. |
Max 32 characters |
|
| validity |
no |
Number of days poll should be kept open for voting. |
Positive Integer |
14 |
| style |
no |
Color code for the style to be used on this poll. |
0, 1, 2, 3 |
0 |
| access |
no |
Whether this poll is public, and should appear in littlepolls directory,
allow users to vote; or it is a private poll (only users who know the poll URL
will be able to vote.) |
public private |
public |
| question |
yes |
Contains 1 question element, and 2-4 answer elements. |
| q |
yes |
Poll Question |
Max 128 characters |
|
| a |
yes |
Poll Answer |
Max 64 characters |
|
Back To Top
XML Response
Here are example Response XML as per your response level selected, followed by
an explanation of the elements. The response XML below are for the same request,
and hence only differ in the amount of detail (level).
Level can be specified by using the level attribute.
Sample XML Response - level "url"
Choose this level if you only need the Poll URL as response from the API.
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<poll myid="MY_POLLID" lpid="1">
<url>http://littlepolls.com/lp1</url>
</poll>
</response>
Sample XML Response - level "simple"
Choose this level if you only need the Poll URL, post message status, and result
URLs as response from the API.
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<poston server="twitter" status="0"
statusmsg=""/>
<poll myid="MY_POLLID" lpid="1">
<url>http://littlepolls.com/lp1</url>
<result>
<url>http://littlepolls.com/lr1</url>
<xml>http://littlepolls.com/xml/22175bb5f5bc6b1f5dbaff828591efa7.xml</xml>
</result>
<votes>0</votes>
</poll>
</response>
Sample XML Response - level "advanced"
Choose this level if you need all details.
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<server domain="mydomain.com" user="MY_USERID"/>
<poston server="twitter" status="0"
statusmsg=""/>
<poll myid="MY_POLLID" lpid="1">
<url>http://littlepolls.com/lp1</url>
<embed><![CDATA[<script type="text/javascript"
language="javascript"
src="http://littlepolls.com/polls/1.js"></script><noscript>
<a href ="http://littlepolls.com/" >Little Polls</a> -
<a href ="http://littlepolls.com/lp1" >Take My Poll</a>
</noscript>]]></embed>
<result>
<url>http://littlepolls.com/lr1</url>
<xml>http://littlepolls.com/xml/22175bb5f5bc6b1f5dbaff828591efa7.xml</xml>
</result>
<votes>0</votes>
</poll>
</response>
Explanation of XML Elements
| Element / Attribute |
Explanation |
| server |
Your server identification |
| domain |
Your domain name. |
| user |
userID of end-user on your server. |
| poston |
Social Network to post the poll on. |
| server |
Social Network Identifier. |
| status |
If success, 0, else Error Code |
| statusmsg |
Detailed Error Message |
| poll |
Poll Details |
| myid |
A Poll ID of your choice |
| lpid |
Littlepolls poll ID. |
| url |
Littlepolls poll URL (share this url with your friends to vote) |
| embed |
Littlepolls poll embed code (to show the poll on any website.) |
| result |
Poll Result |
| url |
Littlepolls poll result URL (share this url with friends to show them
results.) |
| xml |
Littlepolls poll result in XML format. |
| rss |
Littlepolls poll result in RSS format. |
| votes |
No of Votes on this poll. |
Poll Results
Littlepolls API returns you the poll result URL, and result XML URL when you
create the poll. This URL is available in response when response level is simple or advanced.
( See result. )
Back To Top
PHP Client
We have written a sample PHP Client, which will manage XML Requests, and
Response for you.
Sample Code
A Sample PHP code demonstrating how the client can be used to create polls.
Back To Top
Constructor: littlepolls()
Back To Top
Method: createPoll()
function createPoll($response, $server, $poston, $poll, $questions)
Back To Top
Method: getError()
function getError()
Back To Top
Method: getErrorString()
function getErrorString()
Back To Top
Method: getURL()
function getURL()
Back To Top
Method: getEmbedCode()
function getEmbedCode()
Back To Top
API Response Configuration
$response = array(
'responsetype' => 'xml',
'level' => 'advanced'
);
Back To Top
Requesting Server Identification
$server = array(
'domain' => 'mydomain.com',
'user' => 'myuser'
);
Back To Top
Post Your Poll On Social Networks
$poston = array(
'server' => 'twitter',
'user' => 'littlepolls',
'passkey' => 'twitter123',
'message' => '{{user}} wants you to vote on the poll - {{question}}
- {{url}}'
);
Back To Top
Configure Your Poll
$poll = array(
'myid' => 1,
'validity' => 14,
'style' => 0,
'access' => 'public'
);
Back To Top
Configure Poll Questions
$questions = array();
for($i=1;$i<=4;$i++)
{
if($_REQUEST['q' . $i])
{
$questions[$i] = array(
'question' => $_REQUEST['q' . $i],
'answers' => array()
);
for($j=1;$j<=4;$j++)
if($_REQUEST['a' . $i . '' . $j])
$questions[$i]['answers'][$j] = $_REQUEST['a' . $i . '' .
$j];
}
}
Back To Top
Poll Styles
Little Polls currently provides 4 different poll style templates.
Style Code 0
 |
Style Code 1
 |
Style Code 2
 |
Style Code 3
 |
Back To Top
Error Codes
More details can be found by calling
getErrorString() method.
| Error Code
| Explanation |
| 0 |
No Error. Yay! |
| 100 |
HTTP Error connecting to LittlePolls server. |
Back To Top