我有以下代码。在第一阶段(获取OAuth令牌)期间一切正常,但在回调中(在获取访问令牌期间)我得到签名无效错误。有谁能帮我解答我做错了什么?
public ActionResult LinkedInTest(string text)
{
var credentials = new OAuthCredentials
{
CallbackUrl = "http://localhost:60739/Calendar/Callback",
ConsumerKey = ApiKey,
ConsumerSecret = ApiSecret,
Verifier = "123456",
Type = OAuthType.RequestToken
};
var client = new RestClient {Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials};
var request = new RestRequest {Path = "requestToken"};
RestResponse response = client.Request(request);
token = response.Content.Split('&')[0].Split('=')[1];
textToPost = text;
Response.Redirect("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + token);
return null;
}
public ActionResult Callback()
{
token = Request["oauth_token"];
verifier = Request["oauth_verifier"];
var credentials = new OAuthCredentials
{
ConsumerKey = ApiKey,
ConsumerSecret = ApiSecret,
Token = token,
TokenSecret = "",
Verifier = verifier,
Type = OAuthType.AccessToken,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
Version = "1.0"
};
var client = new RestClient
{
Authority = "https://api.linkedin.com/uas/oauth",
Credentials = credentials,
Method = WebMethod.Post
};
var request = new RestRequest {Path = "accessToken"};
RestResponse response = client.Request(request);
return Content(response.Content);
}
答案 0 :(得分:0)
使用LinkedIn REST API的优秀指南:
http://www.suddenelfilio.net/2010/08/24/linkedin-oauth-using-hammock-in-csharp-asp-net/