Josh Earl
Josh Earl

Reputation: 18361

Authenticating to Trello API using RestSharp

I'm struggling a bit to figure out how to use Trello's OAuth API calls from my Windows Phone 7 app. The API isn't really documented, aside from a listing of the endpoints.

Here's what I have so far:

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);
}

I'm getting a 404 response, so something's not right, obviously.

Any suggestions?

Upvotes: 4

Views: 975

Answers (3)

Don Potbury
Don Potbury

Reputation: 21

I think your base url is incorrect. Please try the following:

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

Upvotes: 2

Daniel LeCheminant
Daniel LeCheminant

Reputation: 51091

Not using the ExecuteAsync seems to make it work:

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

At one point "oAuth1 is not yet supported in async scenarios (SL and WP)", according to this post by John Sheehan.

Upvotes: 3

John Sheehan
John Sheehan

Reputation: 78132

Replace OAuthGetRequestToken with authorize.

Upvotes: 1

Related Questions