2013-10-15 175 views
2

使用OAuth,我試圖驗證Web窗體項目Etsy的API。欲瞭解更多信息,請閱讀獲取必要的憑證:OAuth C#1.0 Etsy API

http://www.etsy.com/developers/documentation/getting_started/oauth

在下面的代碼,我的驗證網址回報:

https://openapi.etsy.com/v2/oauth/request_token?oauth_token=xyz 

當我在瀏覽器中訪問它,我收到一個丟失的錯誤簽名。我假設我的網址不正確。 Etsy文檔說我應該獲得登錄url參數。我如何從我的代碼中獲得它?

var consumerContext = new OAuthConsumerContext 
{ 
    SignatureMethod = SignatureMethod.HmacSha1, 
    ConsumerKey = consumerKey, 
    ConsumerSecret = consumerSecret, 
    UseHeaderForOAuthParameters = true 
}; 

var session = new OAuthSession(consumerContext, 
    "https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r", 
    "https://openapi.etsy.com/v2/oauth/request_token", 
    "https://openapi.etsy.com/v2/oauth/request_token"); 

IToken requestToken = session.GetRequestToken(); 
string authorisationUrl = session.GetUserAuthorizationUrlForToken(requestToken); 
link1.NavigateUrl = authorisationUrl; 

回答

2

我有錯誤的URL作爲第三和第四arguent爲OAuthSession:

 public string GetAuthorizationUrl() 
    { 
     var consumerContext = new OAuthConsumerContext 
     { 
      SignatureMethod = SignatureMethod.HmacSha1, 
      ConsumerKey = m_ConsumerKey, 
      ConsumerSecret = m_ConsumerKeySecret, 
      UseHeaderForOAuthParameters = true 
     }; 

     var session = CreateSession(); 

     requestToken = session.GetRequestToken(); 
     System.Web.HttpContext.Current.Session["EtsyRequestToken"] = requestToken; 
     return session.GetUserAuthorizationUrlForToken(requestToken); 
    } 

OAuthSession CreateSession() 
    { 
     OAuthConsumerContext consumerContext = new OAuthConsumerContext 
     { 
      ConsumerKey = m_ConsumerKey, 
      ConsumerSecret = m_ConsumerKeySecret, 
      SignatureMethod = SignatureMethod.HmacSha1 
     }; 

     OAuthSession session = new OAuthSession(consumerContext, "https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r", 

"https://www.etsy.com/oauth/signin", 

"https://openapi.etsy.com/v2/oauth/access_token"); 
     session.CallbackUri = new Uri(m_ReturnUri); 
     return session; 
    } 

我使用的Web API。以下是我使用的庫:

<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net40" /> 
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" /> 
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net40" /> 
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net40" /> 
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" /> 
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" /> 
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" /> 
<package id="RestSharp" version="104.2.0" targetFramework="net40" /> 
+0

您使用了哪種Oauth軟件包?我正在試圖弄清楚如何使用ASP.NET webPages來調用etsy api來調用C# – Frank

+0

嗨,我使用了這段代碼:http://pastebin.com/bUiRwDr4我願意向你推銷一個庫, Etsy並將其解析爲強類型類。請與我聯繫洽談。 –

+0

謝謝!我們不想管理訂單,但如果事情發生變化,我會通過電子郵件發送給您。目前,我們的目標是能夠在mysql和etsy之間同步列表。非常多的發佈,並將現有的MySQL記錄從電子商務網站更新爲etsy列表。 – Frank