<?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_size
signatures will be returned, offset by thepage
number given.
Field Name Type Description signature_count
int
The number of total signatures on this petition. prev_page_endpoint
string
The API endpoint that can be called to retrieve the previous page of signatures. null
if there is no previous page.next_page_endpoint
string
The API endpoint that can be called to retrieve the next page of signatures. null
if there is no next page.page
int
The current page number. total_pages
int
The total number of pages of signatures (of size specified by page_size
)signatures
array
The array of signatures. The signatures array contains objects with the following data:
Field Name Type Description name
string
Full display name of the signer. city
string
Residential city of the signer. state_province
string
(If available) The standard abbreviation of the state or province of the signer. country_name
string
Full English name of the country of the signer. country_code
string
The two-letter code of the country of the signer. signed_on
string
of ISO-8601 datetimeDate and time of the signature.