我正在开发一个桌面应用程序,用户可以使用etsy api创建列表。根据etsy支持,如果有人访问自己的商店,则不需要完全访问权限。然而,我收到以下错误:
任何帮助都将不胜感激。
这是代码:
var baseUrl = "http://openapi.etsy.com/v2/listings";
restClient = new RestClient(baseUrl);
oAuth = new OAuthBase();
e1 = new Etsy_portal(consumerKey, consumerSecret);
string str = e1.GetConfirmUrl(out AccessToken, out AccessTokenSecret);
e1.ObtainTokenCredentials(AccessToken, AccessTokenSecret, verifiedToken, out PAccessToken, out PAccessTokenSecret);
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string normalizedUrl;
string normalizedRequestParameters;
string sig = oAuth.GenerateSignature(new Uri(baseUrl + MethodLocation), consumerKey, consumerSecret, PAccessToken, PAccessTokenSecret,
"Post", timeStamp, nonce,
OAuth.OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);
restClient = new RestClient(baseUrl);
var request = new RestRequest();
request.AddParameter("api_key", consumerKey);
request.AddParameter("oauth_consumer_key", consumerKey);
request.AddParameter("oauth_token", PAccessToken);
request.AddParameter("oauth_nonce", nonce);
request.AddParameter("oauth_timestamp", timeStamp);
request.AddParameter("oauth_signature", sig);
request.AddParameter("oauth_signature_method", "HMAC-SHA1");
request.AddParameter("oauth_version", "1");
request.AddParameter("title", "This is a test");
request.AddParameter("description", "Test Description");
request.AddParameter("quantity", "1");
request.AddParameter("price", "5");
request.AddParameter("is_supply", "false");
request.AddParameter("when_made", "2010_2017");
request.AddParameter("who_made", "i_did");
request.Method = Method.POST;
IRestResponse resRes = restClient.Execute(request);
答案 0 :(得分:0)
var baseUrl = "http://openapi.etsy.com/v2/listings";
restClient = new RestClient(baseUrl);
oAuth = new OAuthBase();
e1 = new Etsy_portal(consumerKey, consumerSecret);
string str = e1.GetConfirmUrl(out AccessToken, out AccessTokenSecret);
e1.ObtainTokenCredentials(AccessToken, AccessTokenSecret, verifiedToken, out PAccessToken, out PAccessTokenSecret);
sigHasher = new HMACSHA1(new ASCIIEncoding().GetBytes(string.Format("{0}&{1}", consumerSecret, PAccessTokenSecret)));
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string normalizedUrl;
string normalizedRequestParameters;
var data = new Dictionary<string, string> {
{ "title", "This is a test1" },
{ "description", "Test Description1" },
{ "quantity", "1" },
{ "price", "5" },
{ "is_supply", "false" },
{ "state", "draft" },
{ "when_made", "2010_2017" },
{ "who_made", "i_did" },
{ "shipping_template_id", "43862539760" }
};
data.Add("oauth_consumer_key", consumerKey);
data.Add("oauth_signature_method", "HMAC-SHA1");
data.Add("oauth_timestamp", timeStamp);
data.Add("oauth_nonce", nonce); // Required, but Twitter doesn't appear to use it, so "a" will do.
data.Add("oauth_token", PAccessToken);
data.Add("oauth_version", "1.0");
data.Add("oauth_signature", GenerateSignature(baseUrl, data));
string oAuthHeader = GenerateOAuthHeader(data);
var formData = new FormUrlEncodedContent(data.Where(kvp => !kvp.Key.StartsWith("oauth_")));
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Add("Authorization", oAuthHeader);
var httpResp = http.PostAsync(baseUrl, formData);
var respBody = httpResp.Result;
}