$api_key = '1a1fdd375286e22801c0da1416d477e0608f5db275301cbe55f1b5314b791ABC';
$secret_token = '7a38898cf6a85e8222cfb55ce2aea60186980353af5ce539dafccd5a3ca1aABC';
$petition_id = 3776824;
$host = 'https://api.change.org';
$endpoint = "/v1/petitions/$petition_id/auth_keys";
$request_url = $host . $endpoint;
$params = array();
$params['api_key'] = $api_key;
$params['source_description'] = 'This is a test description.'; // Something human readable.
$params['source'] = 'test_source'; // Eventually included in every signature submitted with the auth key obtained with this request.
$params['requester_email'] = 'azr...@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;
// 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
$curl_session = curl_init();
curl_setopt_array($curl_session, array(
CURLOPT_POST => 1,
CURLOPT_URL => $request_url,
CURLOPT_POSTFIELDS => $query,
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($curl_session);
$result = curl_exec($curl_session);
$json_response = json_decode($result, true);
print_r($json_response);
{"result":"failure","messages":["Invalid request signature."]}
$api_key = 'd40bc3a30f491ee2ebd20124b0039edb6dafb66397e9721789454df1393e8041';
$secret = '73f8fd7622aabd8ed40e205beb8f1345334850b8ec49f82fb1ef0acb01fc329a';
$petition_id = 8687210;
$host = 'https://api.change.org';
$endpoint = "/v1/petitions/$petition_id/auth_keys";
$request_url = $host . $endpoint;
$params = array();
$params['api_key'] = $api_key;
$params['source_description'] = 'YouTube video'; // Something human readable.
$params['source'] = 'http://www.youtube.com/watch?v=AayLwwvn77s'; // Eventually included in every signature submitted with the auth key obtained with this request.
$params['requester_email'] = 'watson....@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;
// 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
$curl_session = curl_init();
curl_setopt_array($curl_session, array(
CURLOPT_POST => 1,
CURLOPT_URL => $request_url,
CURLOPT_POSTFIELDS => $query,
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($curl_session);
$json_response = json_decode($result, true);
print_r($json_response);