Twitter api 1.1 users/search 403


#1

I have one problem connected with twitter api. I try to search user through twitter api 1.1 in c#. Here is my code:

using (WebClient client = new WebClient())
{

    client.Headers.Add("Authorization", "Bearer " + GetAccessToken());

    var url = "https://api.twitter.com/1.1/users/search.json?q=Twitter";

    return client.DownloadString(url);

}

private string GetAccessToken()
{
    var tokenPayload = string.Empty;

    using (var wc = new WebClient())
    {
        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        wc.Headers.Add("Authorization", "Basic " + GetKeySecretString());

        tokenPayload = wc.UploadString("https://api.twitter.com/oauth2/token", "grant_type=client_credentials");
    }

        return ExtractAccessTokenFromResponse(tokenPayload);
}

But when I try to get response I get 403 forbidden exception. Token is right, because if I search twitts with https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name it works. What am I doing wrong?


#2

I tried to use LINQToTwitter. When I tried to search user I had this exception: Your credentials do not allow access to this resource.


#3

You’re probably using auth and the API correctly, but the users/search method doesn’t support application-only auth – only user accounts can search for other user accounts.


#4

Problem was solved. I sent wrong header. Here is a good article about twitter authentification: http://www.codeproject.com/Articles/247336/Twitter-OAuth-authentication-using-Net