Get signature count

130 views
Skip to first unread message

Tom Vile

unread,
Jun 3, 2014, 9:18:50 PM6/3/14
to change-...@googlegroups.com

Just looking for some php code to get the signature count of my petition.

Any help will be appreciated.

Tom Vile

unread,
Jun 15, 2014, 11:52:52 AM6/15/14
to change-...@googlegroups.com
Anyone have a suggestion?

Nick Batts

unread,
Jun 19, 2014, 5:38:46 PM6/19/14
to change-...@googlegroups.com
This PHP function takes 1 Change.org petition url and returns its signature count. Be sure to replace API_KEY with your api key.

// get signatures for a Change.org petition
function getChangePetitionSignatureCount($url){
 $CHANGE_API_KEY
= 'API_KEY';
 $CHANGE_REQUEST_URL
= 'https://api.change.org/v1/petitions/get_id';
 $parameters
= array(
 
'api_key' => $CHANGE_API_KEY,
 
'petition_url' => $url
 
);
 $query_string
= http_build_query($parameters);
 $final_request_url
= "$CHANGE_REQUEST_URL?$query_string";
 $response
= file_get_contents($final_request_url);
 $json_response
= json_decode($response, true);
 $petition_id
= $json_response['petition_id'];
 
//now get the petition details for signature count
 $CHANGE_REQUEST_URL
= 'https://api.change.org/v1/petitions';
 $parameters
= array(
 
'api_key' => $CHANGE_API_KEY,
 
'petition_ids' => $petition_id
 
);
 $query_string
= http_build_query($parameters);
 $final_request_url
= "$CHANGE_REQUEST_URL?$query_string";
 $response
= file_get_contents($final_request_url);
 $json_response
= json_decode($response, true);
 $petition
= $json_response['petitions'][0];
 $sig_count
= $petition['signature_count'];
 
//var_dump($json_response);
 
return $sig_count;
}

Tom Vile

unread,
Jun 19, 2014, 6:53:47 PM6/19/14
to change-...@googlegroups.com
Thanks! Works great.
Reply all
Reply to author
Forward
0 new messages