<?php
// get signatures for a Change.org petition
function getChangePetitionSignatureCount($url){
$CHANGE_API_KEY = 'PUT-YOUR-API-KEY-HERE';
$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;
}
?>
<?php echo
getChangePetitionSignatureCount("https://www.change.org/p/PUT-THE-URL-OF-THE-PETITION-U-WANT-HERE");
?>Response Data
An array of signatures. A maximum of
page_sizesignatures will be returned, offset by thepagenumber given.
Field Name Type Description signature_countintThe number of total signatures on this petition. prev_page_endpointstringThe API endpoint that can be called to retrieve the previous page of signatures. nullif there is no previous page.next_page_endpointstringThe API endpoint that can be called to retrieve the next page of signatures. nullif there is no next page.pageintThe current page number. total_pagesintThe total number of pages of signatures (of size specified by page_size)signaturesarrayThe array of signatures. The signatures array contains objects with the following data:
Field Name Type Description namestringFull display name of the signer. citystringResidential city of the signer. state_provincestring(If available) The standard abbreviation of the state or province of the signer. country_namestringFull English name of the country of the signer. country_codestringThe two-letter code of the country of the signer. signed_onstringof ISO-8601 datetimeDate and time of the signature.