Answer the question
In order to leave comments, you need to log in
How to pass additional parameters when using OAuth?
Good afternoon!
You need to get a list of all API orders from etsy.com.
The problem is that when passing any of the parameters, I get an error. For example, I pass limit=10 :
oauth_problem=signature_invalid &debug_sbs=GET&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Fshops%2FWoodPecStudio%2Freceipts&limit%3D10%26oauth_consumer_key..
function buildBaseString($baseURI, $method, $params)
{
$r = array();
ksort($params);
foreach($params as $key=> $value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth)
{
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=> $value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = "https://openapi.etsy.com/v2/shops/".ETSY_PROJECT."/receipts";
$oauth_access_token = ETSY_OAUTH_TOKEN;
$oauth_access_token_secret = ETSY_OAUTH_SECRET;
$consumer_key = ETSY_KEY;
$consumer_secret = ETSY_SECRET;
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0',
);
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$header = array(buildAuthorizationHeader($oauth), 'Expect:', 'Content-Type: application/json');
$options = array( CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
#$return_data = json_decode($json);
print_r($json);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question