【问题标题】:Authenticating to Trello API using RestSharp使用 RestSharp 对 Trello API 进行身份验证
【发布时间】:2012-05-09 04:18:33
【问题描述】:

我正在努力弄清楚如何从我的 Windows Phone 7 应用程序中使用 Trello 的 OAuth API 调用。除了listing of the endpoints,API 并没有真正记录在案。

这是我目前所拥有的:

public void OnAuthenticateClicked(object sender, EventArgs e)
{
    const string consumerKey = "mykey";
    const string consumerSecret = "mysecret";
    const string baseUrl = "https://trello.com/1";

    var client = new RestClient(baseUrl) 
    {
        Authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret)
    };
    var request = new RestRequest("OAuthGetRequestToken", Method.POST);
    var response = client.ExecuteAsync(request, HandleResponse);
}

private void HandleResponse(IRestResponse restResponse)
{
    var response = restResponse;
    Console.Write(response.StatusCode);
}

我收到了404 的回复,所以很明显有些地方不对劲。

有什么建议吗?

【问题讨论】:

  • 谢谢,但这也没用。
  • 如果您不使用 ExecuteAsync(例如IRestResponse response = client.Execute(request);),它是否有效?这使得第一步(OauthGetRequestToken 位)对我有用。

标签: windows-phone-7 oauth restsharp trello


【解决方案1】:

将 OAuthGetRequestToken 替换为授权。

【讨论】:

  • 感谢您的回复,约翰。试过了,但我仍然收到404。当我使用OAuthGetRequestToken 时,RequestUri 的格式正确,指向trello.com/1/https://trello.com/1/OAuthGetRequestToken,这似乎是正确的。我试图从 RestSharp 集成测试中解决这个问题,但如何将你在那里所做的事情映射到 Trello 调用并不明显。
  • 没关系,我在使用手机时没有看到 OAuth URL 部分。非 oauth 版本看起来几乎更简单。您是否考虑过使用它?
  • 好建议。事实证明,这实现起来非常简单,尽管我并不热衷于从 HTML 响应中解析令牌。看起来很脆弱。从长远来看,OAuth 似乎是“正确”的方式,但现在我将采取更简单的方式。
【解决方案2】:

不使用ExecuteAsync 似乎可以正常工作:

RestRequest request = new RestRequest("OAuthGetRequestToken", Method.POST);
IRestResponse response = client.Execute(request);
Console.Write(response.StatusCode);

根据 John Sheehan 的 this post 的说法,“异步场景(SL 和 WP)中尚不支持 oAuth1”。

【讨论】:

  • 有趣的观察。感谢您尝试。不幸的是,Windows Phone 只支持异步调用。但这确实给了我一个调查的载体。
  • @JoshEarl 似乎 OAuth 1.0 一度不支持异步,我不确定这是否仍然正确。
【解决方案3】:

我认为您的基本网址不正确。 请尝试以下方法:

const string baseUrl = "https://api.trello.com/1";

【讨论】:

    猜你喜欢
    • 2014-05-12
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-30
    • 2020-09-05
    • 1970-01-01
    • 2013-06-24
    相关资源
    最近更新 更多