I using the following code to find people on twitter. but it gives me authentication issue(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 issue. or any other way to get peoples profiles form the twitter.
Thanks
You cannot use basic authentication (username/password in plain text) with the Twitter API.
I would suggest you use a pre-made library (see: https://dev.twitter.com/docs/twitter-libraries#dotnet) to perform the OAuth ‘stuff’ for you.
When you register an application with Twitter, they will give you pre-generated keys (called a token) for your user. You can perform the search by using that token.