.NET 中的 Delicious API 和 Yahoo oAuth
事实上,Delicious 有两组 API 身份验证,一组使用用户名和密码,一组使用 oAuth,这告诉了我一些我将要经历的事情,我没有错。不幸的是,我现在必须处理这两个 API,但未能成功克服 API v2 (Yahoo oAuth) 的第一个障碍。
下面是一个代码片段(我在本例中使用 OpenSocial http://code. google.com/p/opensocial-net-client)
public static string GetRequestToken(string callbackUrl)
{
string normaluri;
string normaluriparam;
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string sig = oAuth.GenerateSignature(new Uri(TOKEN_URL), ConfigurationManager.AppSettings[CONSUMER_KEY],
ConfigurationManager.AppSettings[SECRET_KEY],
string.Empty,
string.Empty,
"GET",
timeStamp,
nonce,
OAuthBase.SignatureTypes.HMACSHA1,
out normaluri,
out normaluriparam);
sig = HttpUtility.UrlEncode(sig);
string result =
HttpClient.Get(TOKEN_URL, new
{
oauth_nonce = nonce,
oauth_timestamp = timeStamp,
oauth_consumer_key = ConfigurationManager.AppSettings[CONSUMER_KEY],
oauth_signature_method = "HMAC-SHA1",
oauth_signature = sig,
oauth_version = "1.0",
oauth_callback = callbackUrl
});
return result;
}
如果我按照 http://delicious.com/help/oauthapi 我自己将其留给 OpenSocial,我从服务器收到“401 未经授权”,没有进一步的信息。
我发现很多人都有同样的问题,但找不到任何解决方案。
The fact that Delicious has two sets of API authentications one with username and password and one with oAuth told me something about things I was going to experience and I wasn't wrong. Unfortunately I have to deal with both APIs now and am unsuccessful getting through the first hurdle of API v2 (Yahoo oAuth).
Here is a code snippet (I'm using OpenSocial in this example http://code.google.com/p/opensocial-net-client)
public static string GetRequestToken(string callbackUrl)
{
string normaluri;
string normaluriparam;
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string sig = oAuth.GenerateSignature(new Uri(TOKEN_URL), ConfigurationManager.AppSettings[CONSUMER_KEY],
ConfigurationManager.AppSettings[SECRET_KEY],
string.Empty,
string.Empty,
"GET",
timeStamp,
nonce,
OAuthBase.SignatureTypes.HMACSHA1,
out normaluri,
out normaluriparam);
sig = HttpUtility.UrlEncode(sig);
string result =
HttpClient.Get(TOKEN_URL, new
{
oauth_nonce = nonce,
oauth_timestamp = timeStamp,
oauth_consumer_key = ConfigurationManager.AppSettings[CONSUMER_KEY],
oauth_signature_method = "HMAC-SHA1",
oauth_signature = sig,
oauth_version = "1.0",
oauth_callback = callbackUrl
});
return result;
}
It seems it doesn't matter if I follow instructions at http://delicious.com/help/oauthapi myself of leave it to OpenSocial, I get an "401 Unauthorized" from the server with no further info.
I can see many people have the same issue but couldn't find any resolution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是“此阶段不要使用 HMAC-SHA1。而且我忘记将callbackUrl 包含到我的签名中。
The answer is "don't use HMAC-SHA1 for this stage. Also I forgot to include callbackUrl into my signature.