Getting number of signatures by source

83 views
Skip to first unread message

Ben Berman

unread,
Dec 11, 2015, 10:38:50 AM12/11/15
to Change.org API
Is there a way to get the number of signatures on a petition from a particular source?

Rob Weatherall

unread,
Dec 11, 2015, 11:01:59 AM12/11/15
to Change.org API
I think the support for API is dead, I have not seen anyone from change on in a long time.

Give me a few moments, I am currently doing this right now.
If I get success Ill post my code.

Rob Weatherall

unread,
Dec 11, 2015, 11:10:43 AM12/11/15
to Change.org API
<?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");
?>


Ben Berman

unread,
Dec 11, 2015, 11:15:34 AM12/11/15
to Change.org API
Hey Rob. Thanks so much for the response, but it seems to me that this gets the total number of signatures, not the number of signatures from a particular source.

Rob Weatherall

unread,
Dec 11, 2015, 11:23:03 AM12/11/15
to Change.org API
Sorry,I missed the source part.
I prob can't help then.

What do you mean by source? From what page it was signed? like api or on change dot org?

Ben Berman

unread,
Dec 11, 2015, 11:29:35 AM12/11/15
to Change.org API
When you submit a signature, you have to include a field for "source" (or at least I have been). I think when you sign up for an API key for a particular petition, you also have to register that source. In my case, it's the page they're signing from, but it doesn't strictly matter. It seems to me that there should be a way to get signatures split out by source (just as there should be a way to get signatures split out by country, for example)

Rob Weatherall

unread,
Dec 11, 2015, 11:35:02 AM12/11/15
to Change.org API
I thought that is what you meant,

I agree there should be a way, but there is nothing listed in the docs about it.

I was looking for the same as I'd like to know if people are signing from my page or the change page.


Response Data

An array of signatures. A maximum of page_size signatures will be returned, offset by the page 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 datetime Date and time of the signature.

Ben Berman

unread,
Dec 11, 2015, 11:40:09 AM12/11/15
to Change.org API
Yeah. I thought that included source when I started this project. It also appears to be deprecated (when I try to use it, I get an error with a typo in it that claims that endpoint is deprecated)

Rob Weatherall

unread,
Dec 11, 2015, 12:23:21 PM12/11/15
to Change.org API
With no support or response from Change it is very frustrating.

All I can get is Sig count and overview.

Everything I try says my petition only has 1 page and I can't get any signature info
even with Recent (supposed to give last 10) only returns my petition overview

petition_ids=4604652&signatures/recent

even tried
&petition_ids=4604652&signatures?&page_size=2&page=1&sort=time_desc

and if I try to start on page 2 I get an error because there is only 1 page,
but sig count returns almost 700 signatures.

Rob Weatherall

unread,
Dec 11, 2015, 1:59:40 PM12/11/15
to Change.org API
So I read signatures is depreciated but to use recent

I get the same overview with that as well, maybe recent depreciated as well?
anyone get some recent signatures?

Latest try was

http://api.change.org/v1/petitions/4604652recent?api_key=MY-API-KEY

I think change.org is getting too big and now competing with facebook for the worse (NON) support organization.

Mark Dimas

unread,
Dec 11, 2015, 2:06:42 PM12/11/15
to Change.org API
Hi Rob,

This old version of the Change.org API is largely deprecated and no longer actively supported. However, the remaining endpoints should work as documented. I just did a quick test, and confirmed that http://api.change.org/v1/petitions/4604652/signatures/recent?api_key=MY-API-KEY works, I'm not sure where you got the "http://api.change.org/v1/petitions/4604652recent" link from, but that won't work.

Sorry for any trouble you're having.

Rob Weatherall

unread,
Dec 11, 2015, 2:15:57 PM12/11/15
to Change.org API
I have been hacking away and trying so many ways,
You say "old version"
There is a new version?

I just started using this a week ago, where are new versions?

Rob Weatherall

unread,
Dec 12, 2015, 11:49:48 PM12/12/15
to Change.org API
ahhhhh
come in answer 1 brief ? say nothing about API being dead, then go change Docs in github.......
Reply all
Reply to author
Forward
0 new messages