.NET 中的 Delicious API 和 Yahoo oAuth

发布于 2024-08-26 11:22:24 字数 2167 浏览 7 评论 0原文

事实上,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花随流水 2024-09-02 11:22:24

答案是“此阶段不要使用 HMAC-SHA1。而且我忘记将callbackUrl 包含到我的签名中。

The answer is "don't use HMAC-SHA1 for this stage. Also I forgot to include callbackUrl into my signature.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文