I am only using the GET search/tweets endpoint.
As @james_jory it was working fine for a couple of months until a couple of weeks ago.
The main piece of code (with the task of getting a number of recent tweets inside a given area) is structured as follows:
//1. Build the url with all the parameters we are interested in
for (var i = 0; i < numberOfRequests ; i++)
{
//2. If max_id is defined append it to the url
// - _oAuthCreationService has all the information needed to authenticate the request
// - _searchApiUrl is https://api.twitter.com/1.1/search/tweets.json
// - searchParameters is a Dictionary with all the variables and corresponding values used in the request, for example:
// [q, ]
// [geocode, 33.9835968657262,-117.87334312989,85km]
// [result_type, recent]
// [include_entities, true]
// [count, 100]
// - httpMethod is GET
var authorizationHeader = HttpRequestResponse.GetTwitterHttpWebRequestHeader(_oAuthCreationService,
_searchApiUrl, searchParameters, httpMethod);
// - urlBuilder at this point is something like https://api.twitter.com/1.1/search/tweets.json?q=&geocode=33.9835968657262,-117.87334312989,85km&result_type=recent&include_entities=True&count=100
// - authorizationHeader we trust is correct since the first or second request is issued correctly
var request = HttpRequestResponse.GetRequest(urlBuilder.ToString(), httpMethod, authorizationHeader);
var responseJson = HttpRequestResponse.GetResponse(request);
//3. Do something with responseJson
//4. Get max_id from returned tweets and add it to the searchParameters
}
The other methods used for creating a request and getting a response are:
public static HttpWebRequest GetRequest(string url, string httpMethod, string authorizationHeader)
{
var request = (HttpWebRequest)WebRequest.Create(url);
if (!string.IsNullOrEmpty(authorizationHeader))
{
request.Headers.Add("Authorization", authorizationHeader);
}
request.Method = httpMethod;
request.Timeout = 30 * 1000;
return request;
}
public static string GetResponse(HttpWebRequest request)
{
var responseText = string.Empty;
//Here is where we get stuck and get a WebException for the request timing out
var response = request.GetResponse() as HttpWebResponse;
if (response != null && response.StatusCode != HttpStatusCode.OK)
{
//Deal with error
}
if (response != null)
{
var stream = response.GetResponseStream();
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
responseText = reader.ReadToEnd();
}
}
}
return responseText;
}
I hope this helps!