Twitter Authentication problem when try to search people on twitter from my application


#1

Hello everyone.
I using the following code to find people on twitter. but it gives me authentication problem (i-e) System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse();

my code goes here:

HttpWebRequest client = (HttpWebRequest)WebRequest.Create(“http://api.twitter.com/1/users/search.xml?q=testname”);
var ccache = new CredentialCache();
Uri uri = new Uri(“http://api.twitter.com/1/users/search.xml?q=testname”);
ccache.Add(uri, “Basic”, new NetworkCredential(username, password);
client.Credentials = ccache;
client.Timeout = 20000;
client.PreAuthenticate = true;

    try
    {
        using (HttpWebResponse httpResponse = (HttpWebResponse)client.GetResponse())
        {
            using (Stream stream = httpResponse.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }

}

Can anybody tell me how to handle this problem. or any other way to get peoples profiles form the twitter.
Thanks


#2

You’re attempting to use Basic authorization, which is not supported by the Twitter API.

You’ll need to use OAuth. The following document explains some of the differences between the two protocols, and gives pointers on migrating: https://dev.twitter.com/docs/auth/moving-from-basic-auth-to-oauth

The easiest way to access the API would be to use a client library. We have several .NET libraries listed here: https://dev.twitter.com/docs/twitter-libraries#dotnet


#3

Also, please change your password as soon as possible


#4

non esiste una versione in italiano