User_timeline query only ever returns my own tweets


I’m new to using the Twitter API, so I’ve just been learning it today.

I tried this code:

It works but it looks like the code should be listing the tweets for the guy who wrote the example, because the query he is passing in is his twitter username, however when I run the code I see my own tweets.

I’m trying to learn how to export out tweets from someone I follow, so this code looks like it is close to what I want, but:
a) how to I tell it to access the tweets of a different user, and
b) is there a better way to actually export out the tweets from someone I follow?

I’ve tried changing it to various users (I only followed this guy today so perhaps that is why it wasn’t working?) but I tried entering the id of various other people I follow and no luck - still just my tweets.

Also I noticed the code was using “q=” but the help topic on user_timeline said to use screen_name or user_id, so I tried both of these and still I’m only getting my tweets listed.

My access permissions are “read and write”, which I think should be enough.

Thanks for any help!


Hi @bluesky383 - welcome to the community, and to learning the Twitter API!

I don’t have time to test out the code you’ve linked to right now, but here are a couple of clues:

  • it looks like the code originally used the search API to find Tweets, and then that was commented out and replaced with the user_timeline
  • in search, you’d use the q (query) parameter to pass in the API call, which is what the rest of the code here is using. For GET statuses/user_timeline, you’re right that you should use the screen_name
  • so - in principle - passing screen_name=<target_screen_name> as the parameter should get you back the user timeline of the user you want to access. Note that the account would have to be a publically-accessible one, not a protected one.

Good luck!


Thanks for looking and your comments.
I’ll paste my code in - I’m sure I’ve replaced the “q” with user_id in all the right places.
I’ve tried a number of different users - I always get my tweets back!
I’ve taken my tokens out obviously.

    public string query = "wmarybeard"; // "umerpasha";
    public string url = "";

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

    public void findUserTwitter(string resource_url, string q)

        var authHeader = PrepareAuthHeader(resource_url, q);

        ServicePointManager.Expect100Continue = false;

        // make the request
        var postBody = "user_id=" + 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 = "";
            JArray jsonDat = JArray.Parse(objText);
            for (int x = 0; x < jsonDat.Count(); x++)
                var elements = jsonDat[x];
                foreach (var element in elements)
                    html += element.ToString() + "<br/>";                           

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

    private static string PrepareAuthHeader(string resource_url, string q)
        // oauth application keys
        var oauth_token = //"insert here...";
        var oauth_token_secret =  //"insert here...";
        var oauth_consumer_key = // = "insert here...";
        var oauth_consumer_secret = // = "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}" +

        var baseString = string.Format(baseFormat,

        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(

        // 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}\", " +

        var authHeader = string.Format(headerFormat,
        return authHeader;


screen_name if you’re using a text value of username; user_id if you know the user’s numeric user ID. You should use screen_name in this case.

I just issued twurl "/1.1/statuses/user_timeline.json?screen_name=wmarybeard" and it brought back the correct timeline.

If you don’t include a screen_name or user_id it will default to returning your own logged-in user’s timeline, so I suspect your code is not appending the query parameter on the URL properly for some reason.


Ah - thanks that makes sense - I’m in a meeting now but I’ll look again a bit later.


It looks like you are using user_id with a username. Switch to screen_name and it’ll probably work.


Success! Thanks everyone.


I know this is kinda old, but I am new to using Twitter API and still have a question about this, so I hope you can assist me on this thread.
If I provide the wrong information for screen_name, what is the expected behavior? Should I receive an error message or should I simply receive my own tweets instead?
I’m asking because I was passing, e.g. queryParam("screen_name","mary beard") instead of the correct queryParam("screen_name","wmarybeard"), and I was getting my own tweets instead. Is this the expected behavior?

Thanks in advance
Ps.: I’m using Java