使用OAuth,我正在尝试向Etsy的API验证Web表单项目。有关详细信息,请阅读获取必要的凭据:
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;
答案 0 :(得分:2)
我将错误的网址作为AuthSession的第三个和第四个参数:
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" />