401 Unauthorized

102 views
Skip to first unread message

Alexander Grechukhin

unread,
Jun 24, 2017, 5:49:09 PM6/24/17
to immobilienscout24-development
Hi,

I`m trying to make a simple search request, but always 401 error Unauthorized.
All requests via Two-legged OAuth.

Nothing special - just dummy request without any parameters. Playground returb

$url = "http://rest.immobilienscout24.de/restapi/api/search/v1.0/search/"; # no parameters here - just for test

$timestamp = time();
$nonce = base64_encode(uniqid()); # just unique

$base = 'GET&'.rawurlencode($url).'&'
.rawurlencode("&oauth_consumer_key=".rawurlencode(CONSUMER_KEY)
.'&oauth_nonce='.rawurlencode($nonce)
.'&oauth_signature_method='.rawurlencode('HMAC-SHA1')
.'&oauth_timestamp='.rawurlencode($timestamp)
.'&oauth_version='.rawurlencode('1.0')
);

$key = rawurlencode(CONSUMER_SECRET)."&";
$sig = base64_encode(hash_hmac("sha1", $base, $key, true));

$headers =[
'Authorization: '.rawurlencode('OAuth oauth_nonce="'.$nonce.'",oauth_consumer_key="'.CONSUMER_KEY.'",oauth_signature_method="HMAC-SHA1",oauth_timestamp="'.$timestamp.'",oauth_version="1.0",oauth_signature="'.$sig.'"')
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$a = curl_exec($ch);

CONSUMER_KEY is  Immostat24_v2Key

Where I am wrong? 

Pietro Tallarico@ImmobilienScout24

unread,
Jul 7, 2017, 10:28:22 AM7/7/17
to immobilienscout24-development
Hi,

in order to use the Search API properly, it's necessary to use parameters.

Best,

Pietro
Reply all
Reply to author
Forward
0 new messages