Umer Pasha Blogs

www.umerpasha.com

C# dot net code to get latest tweets using twitter API 1.1

on June 13, 2013

Twitter just recently retired their old API 1.0. The new API requires oAuth. Following code will help you jumpstart to write code in C# to get your tweets.

This is using dot net framework 4.0
I am also using NewtonSoft’s excellent JSON library. You can get it here. Use the dot net 4.0 library and add as a reference to your C# Web project.

You first have to create a twitter app here. Use the oAuth Tool tab to get the 4 tokens/codes that you will be replacing in the code below.


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="myDiv" runat="server">
    
    </div>s
    </form>
</body>
</html>


Default.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;


public partial class _Default : System.Web.UI.Page
{


    public string query = "umerpasha";
//    public string url = "https://api.twitter.com/1.1/users/search.json" ;
    public string url = "https://api.twitter.com/1.1/statuses/user_timeline.json" ;


    protected void Page_Load(object sender, EventArgs e)
    {
        findUserTwitter(url, query);
    }

    public void findUserTwitter(string resource_url, string q)
    {

        // oauth application keys
        var oauth_token = "xxx"; //"insert here...";
        var oauth_token_secret = "xxx"; //"insert here...";
        var oauth_consumer_key = "xxx";// = "insert here...";
        var oauth_consumer_secret = "xxx";// = "insert here...";

        // oauth implementation details
        var oauth_version = "1.0";
        var oauth_signature_method = "HMAC-SHA1";

        // unique request details
        var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
        var timeSpan = DateTime.UtcNow
            - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
        var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();


        // create oauth signature
        var baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                        "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&q={6}";

        var baseString = string.Format(baseFormat,
                                    oauth_consumer_key,
                                    oauth_nonce,
                                    oauth_signature_method,
                                    oauth_timestamp,
                                    oauth_token,
                                    oauth_version,
                                    Uri.EscapeDataString(q)
                                    );

        baseString = string.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString));

        var compositeKey = string.Concat(Uri.EscapeDataString(oauth_consumer_secret),
                                "&", Uri.EscapeDataString(oauth_token_secret));

        string oauth_signature;
        using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
        {
            oauth_signature = Convert.ToBase64String(
                hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
        }

        // create the request header
        var headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " +
                           "oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " +
                           "oauth_token=\"{4}\", oauth_signature=\"{5}\", " +
                           "oauth_version=\"{6}\"";

        var authHeader = string.Format(headerFormat,
                                Uri.EscapeDataString(oauth_nonce),
                                Uri.EscapeDataString(oauth_signature_method),
                                Uri.EscapeDataString(oauth_timestamp),
                                Uri.EscapeDataString(oauth_consumer_key),
                                Uri.EscapeDataString(oauth_token),
                                Uri.EscapeDataString(oauth_signature),
                                Uri.EscapeDataString(oauth_version)
                        );



        ServicePointManager.Expect100Continue = false;

        // make the request
        var postBody = "q=" + Uri.EscapeDataString(q);//
        resource_url += "?" + postBody ;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
        request.Headers.Add("Authorization", authHeader);
        request.Method = "GET";
        request.ContentType = "application/x-www-form-urlencoded";
        var response = (HttpWebResponse)request.GetResponse();
        var reader = new StreamReader(response.GetResponseStream());
        var objText = reader.ReadToEnd();
        myDiv.InnerHtml = objText;/**/
        string html = "";
        try
        {
            JArray jsonDat = JArray.Parse(objText);
            for (int x = 0; x < jsonDat.Count(); x++)
            {
                //html += jsonDat[x]["id"].ToString() + "<br/>";
                html += jsonDat[x]["text"].ToString() + "<br/>";
               // html += jsonDat[x]["name"].ToString() + "<br/>";
                html += jsonDat[x]["created_at"].ToString() + "<br/>";

            }
            myDiv.InnerHtml = html;
        }
        catch (Exception twit_error)
        {
            myDiv.InnerHtml = html + twit_error.ToString();
        }
    }
}
Advertisements

96 responses to “C# dot net code to get latest tweets using twitter API 1.1

  1. hary says:

    hi this working fine , can you tell how to post tweet through this……

    • Umer Pasha says:

      Hi. I have not tried posting tweets yet. But, i guess you will have to create the twitter app with appropriate rights to post. oAuth from the code here should work. Check the API documentation here and focus on POST statuses/update method:

      https://dev.twitter.com/docs/api/1.1

      • Vimal says:

        SIr , I was your web site that’s what i want can u pls provide code or step by step solution as u did here for twitter………?
        How can I add profile pic with the tweets in above solution…….. ?

    • Vimal says:

      Hello Sir,
      Pls can you do something like……….Tweets with profile pic ?
      Latter same thing for Facebook ?

      • Umer Pasha says:

        yes you can. I have done it with Facebook. check my website for a live demo. all the albums are coming from Facebook. in about me section, my picture is whatever the dp I set in Facebook. will put up code on my blogs soon.

      • Ajay says:

        Can i get the code of facebook posts crawling in my web site

    • Vimal says:

      Hello Sir,
      Pls can you do something like……….Tweets with profile pic ?
      Latter same thing for Facebook

      • yashwanth says:

        can u send me d code if u get for getting profile pic and getting images from tweet wat u post

    • Vikash Kumar says:

      Hello sir,

      I am able to get the tweets using any screen_name, nice concept. I tried getting the list of followers using the same concept. https://api.twitter.com/1.1/followers/list.json but am not able to convert the json data to a datatable. Could you please guide me on this. itried with regex to replace the unwanted chars but still doesn’t work

  2. Tam says:

    How to make links working

  3. AQEEL AHMED says:

    in my local machine its working awesome, but on server this error

    Unable to connect to the remote server > System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 199.59.149.232:443 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

  4. prakash says:

    Hi Pasha,

    We are using VS 2008 framework 3.5. How to implement this code. Please suggest me.

    • Umer Pasha says:

      Hi Prakash,

      I dont think there is anything in the code that will be incompatible with dot net 3.5. The only thing I see is that you use Newtonsoft’s framework 3.5 dll as a reference instead of 4.0. rest of the code should work fine. Let us know how it goes.

  5. Davey says:

    Very good blog post. I am close to getting this to work with Microsoft Dynamics CRM application, However, I get Error code 214: Bad authentication data.:(

    The request URL is: https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=aspas10&since_id=342379690448805888

    Authentication Header:
    OAuth oauth_nonce=”**********”, oauth_signature_method=”HMAC-SHA1″, oauth_timestamp=”1372370208″, oauth_consumer_key=”*************”, oauth_token=”**********************”, oauth_signature=”****************”, oauth_version=”1.0″

    My code includes:

    request.Headers.Add(“Authorization”, authHeader);
    request.Method = “GET”;
    request.ContentType = “application/x-www-form-urlencoded”;
    var response = (HttpWebResponse)request.GetResponse();
    return response;

    Any ideas where I am going wrong and why I am getting this error? My code is close to identical to what you have posted.

    • Davey says:

      When debugging my code it seems that I am getting error on this line:
      var response = (HttpWebResponse)request.GetResponse();

      • Satyendra says:

        If err no is 401 then it is authentication or 400 request parameter error. I think please you are generated token or not.

      • Umer Pasha says:

        I agree with Satyendra. Looks like you are failing authentication. Was the oauth_signature generated fine?

      • Davey says:

        Thanks for your reply guys.
        I have managed to get a response now. However,I am getting my own tweets which I do not want.

        I would like to get other people’s tweets. I have tried changing

        var postBody = “q=” + Uri.EscapeDataString(q);//

        to

        var postBody = “screen_name=” + Uri.EscapeDataString(q);//

        q is the user name of someone’s twitter account.
        I get Bad authentication data when I do this. 😦

        Any ideas?

      • nigelgos says:

        @Davey – As well as the line you mention you have modified you also need to change the ‘q’ to screen_name in the baseFormat var.

        var baseFormat = “oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
        “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}”;

  6. Satyendra Prakash says:

    Please go through the below link and obtain a choice as per your requirement.
    https://dev.twitter.com/docs/auth/obtaining-access-tokens

    Happy coding

  7. D. Johnson says:

    I’ve successfully migrated all my Google Reader subscriptions to Feedly (and hopefully they won’t disappear July 1st – many of them are archived posts from since deleted blogs and accounts), but with the implementation of Twitter’s API 1.1 all my Twitter subscriptions haven’t updated since June 11th. I understand that OAuth is now required and you have to get the the consumer key, consumer secret, access token, and access token secret and plug them into some script. (I really don’t know exactly what OAuth is, but I know it’s required.) In fact, I’ve now got three sets of keys as I followed the instructions for obtaining them two days ago, each time thinking I must have done something wrong as I never received the promised e-mail examples for how to actually implement the requests, but when I log into dev.twitter.com/apps all three “applications” are there.

    This is where they lose me. I haven’t written computer code since the early ’80s, so this is a whole new world for me. I do not have a “real” Twitter account but rather a “fake” profile just to be able to subscribe to a few Twitter feeds that Google Reader was unable to access. I do not “tweet.” I do not desire to be “tweeted” to. I simply want to be able to read other people’s public tweets. ALL I want to be able to do is to subscribe to 200-300 Twitter feeds in Feedly, just like I did in Google Reader, and to subscribe to new Twitter feeds I find of interest. Can someone please explain IN PLAIN ENGLISH how to do this? I find plenty of computer code scripts, but I don’t know what to DO with them to make this work! IMO Twitter has shot themselves in the collective foot with this stupid change, but if there’s a workaround I just want to know what it is. Thanks!

    • Umer Pasha says:

      Hi,

      Sorry. Yes, I do not like the whole oAuth thing either. But this is how it is. All social networking sites want more scrutiny over it is who users say they are! I lost a lot of work too because of the whole twitter 1.0 to 1.1 fiasco.

      On the other hand, Google ending Google reader is just plain stupid and inconsiderate.

      I think what you are looking for is the new AOL Reader.

      Also check this chart to see what reader suits your need the best:
      Click here

      Hope any of the above helps!

      Umer

      • D. Johnson says:

        Thanks. AOL Reader looks like a good replacement for Google Reader, but I like Feedly better. Frankly, I don’t want anything to do with AOL. Everyone I know with AOL mail has been hacked, some multiple times, so I don’t care to allow them access to any more of my personal information.

        What I really need help with is subscribing to public Twitter timelines in one place. Whether that is possible in Feedly, AOL Reader, or some other place, that’s what I’m trying to do. I’ve gone through the process of obtaining the consumer key, consumer secret, access token, and access token secret by creating an application. Now I just need to know what to DO with this information. The instructions with the “script” I plugged this information into to get that far stated that I would receive an e-mail with examples of what I assume are ways to do this. Unfortunately, I never received any e-mails even though I went through the process three times. I can see all three applications on the Google site, but I don’t know where to go from there. I’ve got all this “super secret” information and have no clue what to do with it now!

        I understand that Twitter no longer supports RSS feeds and that OAuth is now required, but I don’t understand how (or where) to get public Twitter feeds into one place in a form “like” Google Reader. I don’t have the time to follow 200-300 Twitter users. I just want the data retrieved and downloaded to one place, sorted and filed by user (as opposed to Twitter’s chronological list of everyone’s tweets all dumped together). I could do this with Twitter’s API 1.0 using RSS, but because of the changes with API 1.1 this is no longer possible using the method I’ve used before.

        I just need to know what I need to do, if it’s possible, to accomplish this now. How do I USE the application I developed using the dev.twitter site to retrieve these timelines? I can type a line for each user’s Twitter account if that’s what’s necessary, but I need to know where/what/how to do this. So far I’ve not been able to find that information anywhere.

      • D. Johnson says:

        Found it! Here are the instructions I followed:

        “How to Create RSS Feeds for Twitter API 1.1”

        http://www.labnol.org/internet/twitter-rss-feeds/27931

        I got all the way through Step 3 but never received any e-mails.

    • Umer Pasha says:

      Sorry, I forgot one more thing. You can also create your own widget using twitter’s own widgets. Here is the link:
      https://twitter.com/settings/widgets/new/user

      Let me know if you need help with that.

      • D. Johnson says:

        It appears the purpose of that particular widget is to allow you to download your own Twitter activity to your own website or blog.

        As I tried (maybe not well) to explain above, I simply want to be able to continue reading a large number of Twitter feeds in one place in a form “like” that of Google Reader (R.I.P.).

        I’ve got the “secret codes” for the application I created in Google. How do I get from there to downloading Twitter feeds again?

        Thanks!

  8. gtl says:

    i m not getting the response page is blank..

    thanks in advance..

  9. D. Johnson says:

    I finally got this to work. Sometimes. I’ve had to “deploy” numerous applications and use the various scripts I received by e-mail. (I was using a different address than I thought which is why I thought I was not receiving the e-mails.) Sometimes a script will find 2 or 3 Twitter feeds and then stop working. Another one may work 25-30 times and then inexplicably stop finding any feeds, even feeds I’ve found before. And some will never find a single feed. So it’s been a slow, painstaking process to download all my previous Twitter feeds to Feedly. There are a few that none of the scripts have been able to find even though they’re current and public. It’s working fairly well though. At first it didn’t seem to be updating any feeds, but that seems to have resolved now, too. Thank you for developing this workaround!

  10. Jayesh says:

    Thanks, it worked for me.

    • D. Johnson says:

      Well, it’s not working consistently for me. I’ve had to launch over a dozen versions of the application and get a new script each time. Some would work for a few feeds, some for more, and some for none. Now that I’ve got about 100 Twitter feeds in Feedly, hardly any of them are updating anymore. Most haven’t updated in 3 or 4 days now. Help, please!

  11. Rahana says:

    var postBody = “q=” + Uri.EscapeDataString(q);
    resource_url += “?” + postBody;
    I need to replace the “q” with scree_name or count. When ever I tried this I got 401 Unauthorized error. How can I solve it. It’s urgent . Please help me.

  12. Nate says:

    This worked for me. _cnt is the number of tweets you want returned and _query is screen_name

    // create oauth signature
    var baseFormat = “count={7}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
    “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}”;

    var baseString = string.Format(baseFormat,
    oauth_consumer_key,
    oauth_nonce,
    oauth_signature_method,
    oauth_timestamp,
    oauth_token,
    oauth_version,
    Uri.EscapeDataString(_query),
    _cnt.ToString()
    );

    baseString = string.Concat(“GET&”, Uri.EscapeDataString(_url), “&”, Uri.EscapeDataString(baseString));

    var compositeKey = string.Concat(Uri.EscapeDataString(oauth_consumer_secret),
    “&”, Uri.EscapeDataString(oauth_token_secret));

    string oauth_signature;
    using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
    {
    oauth_signature = Convert.ToBase64String(
    hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
    }

    // create the request header
    var headerFormat = “OAuth oauth_nonce=\”{0}\”, oauth_signature_method=\”{1}\”, ” +
    “oauth_timestamp=\”{2}\”, oauth_consumer_key=\”{3}\”, ” +
    “oauth_token=\”{4}\”, oauth_signature=\”{5}\”, ” +
    “oauth_version=\”{6}\””;

    var authHeader = string.Format(headerFormat,
    Uri.EscapeDataString(oauth_nonce),
    Uri.EscapeDataString(oauth_signature_method),
    Uri.EscapeDataString(oauth_timestamp),
    Uri.EscapeDataString(oauth_consumer_key),
    Uri.EscapeDataString(oauth_token),
    Uri.EscapeDataString(oauth_signature),
    Uri.EscapeDataString(oauth_version)
    );

    ServicePointManager.Expect100Continue = false;

    // make the request
    var postBody = “screen_name=” + Uri.EscapeDataString(_query) + “&count=” + _cnt.ToString();//
    _url += “?” + postBody;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
    request.Headers.Add(“Authorization”, authHeader);
    request.Method = “GET”;
    request.ContentType = “application/x-www-form-urlencoded”;
    var response = (HttpWebResponse)request.GetResponse();
    var reader = new StreamReader(response.GetResponseStream());
    var objText = reader.ReadToEnd();

  13. Rahana says:

    hi.. Nate your code worked for me. But when ever I change the the code

    FROM:

    var baseFormat = “count={7}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
    “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}”;

    To:

    var baseFormat = “oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
    “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}&count={7}”;

    I got the same 401 Unauthorized error. What will be the issue..? Please help me 😦

  14. Nate says:

    I just figured it out, and I am sure there is fine print that indicates it.

    All parameters in the header MUST be in alphabetical order by name to work. So to fix your issue do the following. Just move count={7} to the front of the query string.

    var baseFormat = “count={7}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
    “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}”;

    If the parameters are not in alphabetical order it will come back with an Unauthorized. Bad Programming!!!!!!!

    So if you are going to include any of the parameters they must be in the following order:

    contributor_details
    count
    exclude_replies
    include_entities
    include_rts
    max_id
    oauth_consumer_key
    oauth_nonce
    oauth_signature_method
    oauth_timestamp
    oauth_token
    oauth_version
    page
    screen_name
    since_id
    trim_user
    user_id

  15. D. Johnson says:

    Now that I’ve got a couple hundred Twitter feeds in Feedly, hardly any will update. I have logged out of Feedly, cleared the cache, logged back in, refreshed the page, and nothing changes. What am I doing wrong???

  16. Rahana says:

    Hi.. How can I extract data from objText ( Data retrieved from Twitter) without using external library like Newtonsoft.json. I need complete C#.net code to extract the data. If anyone knows it please help me… 😦

    • Umer Pasha says:

      You will still get the data back with this code even if you do not use Newtonsoft.json. The thing is, then you will have to write your own code to retrieve data in a readable format.

  17. Rahana says:

    Is Newtonsoft.json a freeware…?

  18. Rahana says:

    Can I change the status on Twitter once it is posted..?

  19. Rahana says:

    How can I extract screen_name and name from the json array using Newtonsoft.json.

  20. Rahana says:

    Hi… I need to do the same thing (post,get,delete) with Face Book also . What do I do.
    Help me with sample code… 😦

    • Umer Pasha says:

      Essentially, the same code structure works for facebook if you use facebook’s API instead of Twitter API.

      Though, the recent shift to Graph API has made working with Facebook a lot easier. I ported over my code to use Graph API a year back.

      You will need an authentication token from facebook to access it. Please check apps.facebook.com for that. Again, you will have to create an app and get an authentication token generated with the correct rights.

      Once you do that, you can check the VB code I am using on this port:
      https://umerpasha.wordpress.com/2013/08/01/vb-source-code-to-get-facebook-status-messages-using-graph-api/

      You can see it in action on my homepage here (Use Chrome):
      http://www.umerpasha.com

      I store all my albums in facebook so I am getting all the latest status messages, profile picture and albums from facebook on my page using VB code and JSON objects.

  21. Rahana says:

    Thanks a lot… 🙂 I need to do POST,GET and DELETE on FaceBook page.. not on Timeline.. using c#.net and without using any external library. Is it possible..?
    Please help me 😦

  22. niraj25 says:

    Thanks Nate …..It worked ….One more question -> how to get the user profile picture…..

  23. zeet says:

    Hi, this code works fine. But I’m getting some diff results than what I should? Am I paasing wrong screen name and url?

  24. Josh says:

    I’ve been searching around for a working example, and this was the most straightforward. You saved me a lot of time. Thanks, Nate 🙂

  25. Sasikumar says:

    hai every one
    i use the code but it show me an 401 error what i do
    i check twitter api access token, secrete and consumer token and secrete

  26. Sasikumar says:

    hai i make changes and working fine now it display
    Server Error in ‘/verify’ Application.

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

  27. Sasikumar says:

    Server Error in ‘/verify’ Application.

    The remote server returned an error: (401) Unauthorized.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.

  28. Gabriel says:

    C# dot net code to get latest tweets using twitter API 1.1 … is really big and I (Gabriel) admire 149 c.

  29. Pablo says:

    Nice Post,
    how can i implement this code into a blogengine.net project?

  30. Alexander Schulz says:

    Hi, thank you for your code… did it for me.
    In my case (SharePoint 2010) I had to set the “ServerCertificateValidationCallback” also

    System.Net.ServicePointManager.ServerCertificateValidationCallback +=
    (s, cert, chain, sslPolicyErrors) => true;

  31. very good blog. It’s important for me.

  32. Mujeeb says:

    Hi umer,

    I want to get the replies for this post using twitter api. how can i do it.

    i tried many ways but not getting the replies in web response.

    Help me out in this.

    thanks,
    Mujeeb.

  33. yasar khan says:

    Assalamu-alaikum umer
    I’am yasar khan

    i’am trying to developing an twitter app in unity 3d and that should pull the tweets for a specific hash tag .

    so i don’t know how to import your code in unity 3d,or i should use any library for unity 3d,please help me bro

  34. rjweber says:

    Thank You Thank You Thank You, It worked great for me, but can someone tell me how to exclude retweets. Thanks in advance

  35. Hey could u please explain me how do i “Use the dot net 4.0 library and add as a reference to your C# Web project.”…

  36. Thabang says:

    Thank you so much, this really helped. However, I would like to display another users timeline, i am struggling to embed “screenname” into the code. Please help. Thanks

  37. kiquenet says:

    Now is working with latest version API Twitter ? OAuth 2 ?

  38. kiquenet says:

    Step by Step for get this values ?

    // oauth application keys
    var oauth_token = “xxx”; //”insert here…”;
    var oauth_token_secret = “xxx”; //”insert here…”;
    var oauth_consumer_key = “xxx”;// = “insert here…”;
    var oauth_consumer_secret = “xxx”;// = “insert here…”;

  39. What is JArray ? full code ?

    • Umer Pasha says:

      Can’t really post full code for copyright reasons. But JArray is just an array that stores json data. Please check newtonsoft json library docs for more.

      • kiquenet says:

        More updates about it ?
        I’m newbie with Twitter. and Developer in C#.

        I would like use C# and Twitter and do tasks programmatically.

        ow can I get your all tweets list programatically using C# ?

        And download photos and videos from anyone timeline too C# ?

        How get the list of followers and following using C# ?

        How send DM anyone user using C# ?

        How can I follow to user using C#

        How manage lists using C#?

        Which is the more stable and updated API for Twitter in C# ?

        Now election is TweetSharp vs LinqToTwitter ?

        Thanks a lot

  40. The code works perfectly in returning a Twitter Timeline.
    However it’s returning -mine- instead of the one for “umerpasha”.
    What did I miss in the code?

  41. Ram says:

    i had given “Div17808181” and i used to gave consumer and token values but nothing to show i am getting empty value

  42. aini says:

    I m getting an error “myDiv” doesnot exist in the current context. why? though I didnt change the first line of my “default.aspx”.. it is like this
    @ Page Title=”Home Page” Language=”C#” MasterPageFile=”~/Site.Master” AutoEventWireup=”true” CodeBehind=”Default.aspx.cs” Inherits=”WebApplication2._Default” %>

  43. aini says:

    I want to get posts from a twitter page. What should I change in the code?

  44. Vinothkumar says:

    How to search for tweets based on the hash (#)?

  45. Satya says:

    Hi Pasha, Last time with your help, upgraded old version to new 1.1 to get tweets. Right now my requirement is images or text share to twitter and pinterest.

    Thanks in advance.
    Satya

  46. Satya says:

    we are using asp.net 3.5 and C#

  47. Asad Naeem says:

    Although this code is working fine here. But i want to get all the tweets. What could be the way for that??? I need it urgent. Plzzzzzzzzz

  48. vijeta Sharma says:

    Hi please tell me where tweets are being saved in json file??what is the location of that file???plz tel its urgent.

  49. Manideep says:

    Hi Umerpasha, please tell me the way to retrieve the most recent image of an application from twitter. Thanks.

  50. Gaurav Dixit says:

    its not giving results according to Screen name …. if u change the screen name than also it will give the same result ….
    actually i just want to result according to screen name …. is it possible

  51. Sergio says:

    Hi, The code works, thank you. But I want to look for all tweets, not only mine, that have a particular string.

  52. Sawan says:

    Hi Umer,

    Using the screen_name attribute I am able to display the Tweets and replies by the user twitter user. How can I get only tweets and not the replies?

  53. yashwanth says:

    i need to know about getting profile details like name profice pic and so on…and display image also wen i tweet

  54. Mohit says:

    i want to get json records same as above but i want to pass lat and long with query but when i am putting everything in the base format like i am getting (401) Unauthorized error. i am using url “https://api.twitter.com/1.1/geo/search.json”

    var baseFormat = “oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}” +
    “&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&query={6}&lat={7}&long={8}”;

    can any one help me what i am doing wrong. thanks in advance

  55. […] C# dot net code to get latest tweets using twitter API 1.1 … – Jun 13, 2013  · Hi. I have not tried posting tweets yet. But, i guess you will have to create the twitter app with appropriate rights to post. oAuth from the code here … […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: