I'm trying to do the sample Authorized Request (or anything with Etsy's api that requires authentication) given in their documentation. The response I get is "oauth_problem=token_rejected".
I used this SO answer along with the OAuth base that benSharper linked to.
I've looked at this and this, and others. One of them used https://sandbox.https://openapi.etsy.com/v2
and when I tried that, the exception was "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." I deployed to my server (which is https) and still the same response.
Just can't seem to make it work. What am I missing?
Here's my code:
public class AuthorizedRequestHelper
{
string baseUrl = "https://openapi.etsy.com/v2";
string relativePath = "/oauth/scopes";
string oauth_consumer_key = "xxx";
string consumerSecret = "xxx";
string oauth_token = "xxx";
string oauth_token_secret = "xxx";
public void test()
{
var restClient = new RestClient(baseUrl);
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string normalizedUrl;
string normalizedRequestParameters;
string sig = oAuth.GenerateSignature(new Uri(baseUrl + relativePath), oauth_consumer_key, consumerSecret, oauth_token, oauth_token_secret, "GET", timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
var request = new RestRequest(relativePath);
request.Resource = string.Format(relativePath);
request.Method = Method.GET;
request.AddParameter("oauth_consumer_key", oauth_consumer_key);
request.AddParameter("oauth_token", oauth_token);
request.AddParameter("oauth_nonce", nonce);
request.AddParameter("oauth_timestamp", timeStamp);
request.AddParameter("oauth_signature_method", "HMAC-SHA1");
request.AddParameter("oauth_version", "1.0");
request.AddParameter("oauth_signature", sig);
IRestResponse irestResponse = restClient.Execute(request);
var content = irestResponse.Content;
// content = oauth_problem=token_rejected
}
}
Any help would be greatly appreciated.
Figured out what I was missing. I was missing Obtaining Token Credentials, which are the permanent tokens you need to access protected resources.
Had trouble wrapping my head around OAuth, RestSharp, and Etsy's implementation all at once. Didn't need the OAuthBase, RestSharp takes care of that.
Note that the
appKey
andsharedSecret
becomeconsumerKey
andconsumerSecret
when making OAuth calls with RestSharp.Here's working code:
Pseudo code (with callback):
Etsy_portal
objectCall
GetConfirmUrl
, provide a callback URL. The callback will have two query parametersoauth_token
andoauth_verifier
. Here's an example of a callback function signature:[HttpGet] public ActionResult EtsyCallback(string oauth_token, string oauth_verifier)
Save the returned token and secret in a map structure for later retrieval.
GetConfirmUrl
.ObtainTokenCredentials
to get a permanent token and secret.