petition not found error

17 views
Skip to first unread message

Widi Oremo

unread,
Aug 10, 2015, 7:49:26 AM8/10/15
to Change.org API
//I have the following function
//I keep getting this response {"result":"failure","messages":["petition not found"]}
//I have checked and checked my code again but I cant see what's wrong.
//Kindly assist.


public function get_auth_key(){
    
  $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  $secret_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  $petition_id = xxxxxxx;
  $endpoint = '/v1/petitions/$petition_id/auth_keys';
  $request_url = $host . $endpoint;
  $params = array();
  $params['api_key'] = $api_key;
  $params['source_description'] = 'Petition website'; // Something human readable.
  $params['source'] = base_url(). '/change_dot_org/get_auth_key'; // Eventually included in every signature submitted with the auth key obtained with this request.
  $params['requester_email'] = 'wezxxxxxx...@gmail.com'; // The email associated with your API key and Change.org account.
  $params['timestamp'] = gmdate("Y-m-d\TH:i:s\Z"); // ISO-8601-formtted timestamp at UTC
  $params['endpoint'] = $endpoint;
  $params['callback_endpoint'] = base_url(). '/change_dot_org/get_auth_key';
  
  // Build request signature and add it as a parameter
  $query_string_with_secret_and_auth_key = http_build_query($params) . $secret_token;
  $params['rsig'] = hash('sha256', $query_string_with_secret_and_auth_key);
  // Final request body
  $query = http_build_query($params);
  // Make the request
  
  
  /////////////////////////////////////
  
   $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $request_url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        $response = curl_exec($ch);

        if (curl_errno($ch)) {
            echo curl_error($ch);
            echo "\n<br />";
            $response = '';
        } else {
            curl_close($ch);
        }

        if (!is_string($response) || !strlen($response)) {
            echo "Failed to get contents.";
            $response = '';
        }

        echo $response;

       
        die();
  
  
  
  ////////////////////////////////////
  
}


Reply all
Reply to author
Forward
0 new messages