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?