I've successfully used the example here https://gist.github.com/tonefolder/44191a29454f9059c7e6 to authenticate a user and to store the oauth_token and oauth_token_secret. I can then make authenticated GET requests using cURL.
I don't know how to make authenticated POST requests though.
I have tried using the $result['header'] from the signed oauthObject in this way:
$discogs_username = "'XXXX'";
$result = mysql_query("SELECT * FROM discogs WHERE username = $discogs_username;", $link);
if (mysql_num_rows($result)) {
$discogs_details = mysql_fetch_array($result, MYSQL_ASSOC);
}
$signatures = array(
'consumer_key' => 'MyKey',
'shared_secret' => 'MySecret',
'oauth_token' => $discogs_details['oauth_token'],
'oauth_token_secret' => $discogs_details['oauth_token_secret']
);
$jsonquery = json_encode(array(
'release_id' => '7608939',
'price' => '18.00',
'condition' => 'Mint',
'sleeve_condition' => 'Mint',
'status' => 'For Sale'
)
);
$result = $oauthObject->sign(array(
'path' => $scope.'/marketplace/listings',
'signatures'=> $signatures
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'MyDiscogsClient/0.1 +http://me.com');
curl_setopt($ch, CURLOPT_URL, $result['signed_url']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization:' . $result['header']));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonquery);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = json_decode(curl_exec($ch), true);
curl_close($ch);
But I get '[message] => You must authenticate to access this resource.'
I'm not sure if i'm doing the CURLOPT_POSTFIELDS part correctly, but I can figure that out once i'm actually able to send an authenticated POST! Sorry if there is also loads more wrong with this - I don't use cURL that often!