获取signature_invalid调用的OAuth / request_token使用RestSharp Etsy的的API [英] Getting signature_invalid calling oauth/request_token for Etsy's API using RestSharp

查看:411
本文介绍了获取signature_invalid调用的OAuth / request_token使用RestSharp Etsy的的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 RestSharp 访问Etsy的的API。下面是我用试图获取OAuth访问令牌代码:

I'm trying to use RestSharp to access Etsy's API. Here's the code I'm using attempting to get an OAuth access token:

        var authenticator = OAuth1Authenticator.ForRequestToken(
            ConfigurationManager.AppSettings["ApiKey"],
            ConfigurationManager.AppSettings["ApiSecret"]);

        // same result with or without this next line:
        // authenticator.ParameterHandling = OAuthParameterHandling.UrlOrPostParameters;

        this.Client.Authenticator = authenticator;

        var request = new RestRequest("oauth/request_token")
            .AddParameter("scope", "listings_r");

        var response = this.Client.Execute(request);



Etsy的告诉我,签名是无效的。有趣的是,当我输入由请求产生的时间戳和随机数的值到这个 OAuth的签名验证工具,签名不匹配。此外,通过该工具生成的URL与Etsy的作品,其中由RestSharp产生的一个没有。是不是我做错了或别的东西,我需要RestSharp配置

Etsy tells me that the signature is invalid. Interestingly enough, when I enter the timestamp and nonce values generated by the request into this OAuth signature validation tool, the signatures don't match. Moreover, the URL generated by the tool works with Etsy where the one generated by RestSharp doesn't. Is there something I'm doing wrong or something else I need to configure with RestSharp?

请注意:我使用其的NuGet包,提供的RestSharp的版本,在此张贴时间为102.5。

Note: I'm using the version of RestSharp provided by their Nuget package, which at the time of this posting is 102.5.

推荐答案

我终于能够与使用OAuth RestSharp连接到Etsy的API。这里是我的代码 - 我希望它为你...

I finally was able to connect to the Etsy API with RestSharp using OAuth. Here is my code -- I hope it works for you...

RestClient mRestClient = new RestClient();

//mRestClient.BaseUrl = API_PRODUCTION_URL;
mRestClient.BaseUrl = API_SANDBOX_URL;
mRestClient.Authenticator = OAuth1Authenticator.ForRequestToken(API_KEY, 
                                              API_SHAREDSECRET, 
                                              "oob");

RestRequest request = new RestRequest("oauth/request_token", Method.POST);
request.AddParameter("scope", 
                     "shops_rw transactions_r transactions_w listings_r listings_w listings_d");

RestResponse response = mRestClient.Execute(request);

if (response.StatusCode != System.Net.HttpStatusCode.OK)
   return false;

NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(response.Content);

string oauth_token_secret = queryString["oauth_token_secret"];
string oauth_token = queryString["oauth_token"];

string url = queryString["login_url"];
System.Diagnostics.Process.Start(url);

// BREAKPOINT HERE
string oauth_token_verifier = String.Empty; // get from URL

request = new RestRequest("oauth/access_token");
mRestClient.Authenticator = OAuth1Authenticator.ForAccessToken(API_KEY,
                           API_SHAREDSECRET,
                           oauth_token,
                           oauth_token_secret,
                           oauth_token_verifier);
response = mRestClient.Execute(request);

if (response.StatusCode != System.Net.HttpStatusCode.OK)
  return false;

queryString = System.Web.HttpUtility.ParseQueryString(response.Content);

string user_oauth_token = queryString["oauth_token"];
string user_oauth_token_secret = queryString["oauth_token_secret"];



user_oauth_token和user_oauth_token_secret是用户的访问令牌和访问令牌的秘密 - 这些都是有效的用户直到用户撤销服务。

The user_oauth_token and user_oauth_token_secret are the user's access token and access token secret -- these are valid for the user until the user revokes access.

我希望这代码可以帮助!

I hope this code helps!

这篇关于获取signature_invalid调用的OAuth / request_token使用RestSharp Etsy的的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆