Post signature from my website doesn't work

45 views
Skip to first unread message

Frédéric Lossignol

unread,
Oct 21, 2014, 8:29:06 AM10/21/14
to change-...@googlegroups.com
hello i created 3 petitions via API Change.org
But now, post signature doesnt work.

2 Questions :

1/ what is required parameters to allow signature ?

i have these following parametters (others ?)  :

'//envoi des signatures depuis le formulaire
    // Set my API key and secret token
  $api_key = myApiKey;
  $secret = mySecretKey;

  // Set my authorization key for petition with Change.org ID
  $petition_auth_key = myAuthKey
  $petition_id = myIdPetition

  // Set up the endpoint and URL.
  $base_url = "https://api.change.org";
  $endpoint = "/v1/petitions/$petition_id/signatures";
  $url = $base_url . $endpoint;

  // Set up the signature parameters.
  $parameters = array();
  $parameters['
api_key'] = $api_key;
  $parameters['
timestamp'] = gmdate("Y-m-d\TH:i:s\Z"); // ISO-8601-formtted timestamp at UTC
  $parameters['
endpoint'] = $endpoint;
  $parameters['
source'] = 'monUrlWebSite';
  $parameters['
email'] =  $post_Email;
  $parameters['
first_name'] = $post_First_name;
  $parameters['
last_name'] = $post_Last_name;
  $parameters['
address'] = '';
  $parameters['
city'] = $post_City;
  $parameters['
state_province'] = '';
  $parameters['
country_code'] = $post_Country_code;
  $parameters['
postal_code'] = $post_postal_code;
  $parameters['
phone'] = '';


 

2/ My request is good ?

 
// Build request signature.
  $query_string_with_secret_and_auth_key
= http_build_query($parameters) . $secret . $petition_auth_key;
 
 
// Add the request signature to the parameters array.
  $parameters
['rsig'] = hash('sha256', $query_string_with_secret_and_auth_key);

 
// Create the request body.
  $data
= http_build_query($parameters);

 
// POST the parameters to the petition's signatures endpoint.
 $curl_session
= curl_init();
 curl_setopt_array
($curl_session, array(
   CURLOPT_POST
=> 1,
    CURLOPT_URL
=> $url,
    CURLOPT_POSTFIELDS
=> $data
 
));
 $result
= curl_exec($curl_session);
 $json_response
= json_decode($result, true);
echo
($json_response);




3/ How to have a return of my request ? I cant have any response.



ThanKS.

Fred
Reply all
Reply to author
Forward
0 new messages