1

After Twitter deprecated their Twitter API 1.0, I've tried several methods in order to get the 1.1 API working for my Windows 8 application. However, what you see below is basically what I've ended up with:

    public List<UserTweet.User> jsonFromTwitter;
    private async void fetchTweet()
    {
        var jsonTwitter = new Uri("http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=stackoverflow&result_type=recent");

        HttpClient client = new HttpClient();

        var request = new HttpRequestMessage(HttpMethod.Get, jsonTwitter);

        var oAuthHeader = "OAuth oauth_consumer_key=\"XXXXX\", oauth_nonce=\"XXXXX\", oauth_signature=\"XXXXX\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1318622958\", oauth_token=\"XXXXX-XXXXXX\", oauth_version=\"1.0\"";

        request.Headers.Add("Authorization", oAuthHeader);

        var response = await client.SendAsync(request);


        var responseString = await response.Content.ReadAsStringAsync();

        jsonFromTwitter = JsonConvert.DeserializeObject<List<UserTweet.User>>(await client.GetStringAsync(responseString));

        //listbox.ItemsSource = jsonFromTwitter;
    }

However, this won't do much good, and it switches between mainly a couple of errors. One of them can be seen below, and the other one is "Could not authenticate user" or similar, basically there's something wrong with the headers as far as I've understood.

Out of bounds or "Could not authenticate"

Anyone got any ideas on how to construct a working OAuth header for this? I'm clueless at the moment.

1

There's a lot more you need to do for the value assigned to the Authorization header - plain text won't work. The following pages in the Twitter OAuth documentation might help you get started in the right direction.

  1. Twitter's Docs have a section on Authentication
  2. Authorizing a Request
  3. Creating Signatures
  • You wouldn't know of any libraries or similar which supports Windows 8 and OAuth towards Twitter? – AndreasB Mar 2 '13 at 19:32
  • 1
    @AndrewB Matter of fact, I wrote one. It's called LINQ to Twitter and has full support for Windows 8 (and other profiles): linqtotwitter.codeplex.com – Joe Mayo Mar 2 '13 at 22:51
  • Oh! And that would actually work with Twitter's new OAuth? I guess I know what Sunday will bring now :) – AndreasB Mar 2 '13 at 23:03
  • Yes, it works fine. There are demos on the Samples page (linqtotwitter.codeplex.com/…). You would use WinRtAuthorizer for OAuth, as shown in the demo. – Joe Mayo Mar 3 '13 at 0:36
  • Alright, cool! I'm testing a few different libraries, however none of them are able to fetch information from user_timeline.json?screen_name[some screen name], only get an authentication error. Any ideas? – AndreasB Mar 3 '13 at 19:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.