Hello,
I was playing with the twitter stream (http://stream.twitter.com/1/
statuses/filter.json?track=test) and found that I sometimes get
incomplete json returned. Some responses are complete and others are
not. I don't have an idea why this is and how to solve this.
Here is the C# code to reproduce this:
/*-------------------------------------------------CODE */
byte[] buf = new byte[32768];
String domain = "http://stream.twitter.com/1/statuses/
filter.json?track=" + hash;
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(domain);
request.Credentials = new
NetworkCredential(user_name,user_password);
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
using (response)
{
Stream resStream = response.GetResponseStream();
using (resStream)
{
int count;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data);
if (count != 0)
{
// translate from bytes to ASCII text
string tempString =
Encoding.ASCII.GetString(buf, 0, count);
if (!string.IsNullOrEmpty(tempString) && !
tempString.Equals("null",
StringComparison.InvariantCultureIgnoreCase))
{
try
{
JsonConvert.DeserializeObject(tempString);
}
catch (Exception e)
{
Console.WriteLine("Exception
occured");
}
}
}
} while (count > 0); // any more data to read?
}
}
/*-------------------------------------------------END CODE */
--
Twitter developer documentation and resources: https://dev.twitter.com/doc
API updates via Twitter: https://twitter.com/twitterapi
Issues/Enhancements Tracker: https://code.google.com/p/twitter-api/issues/list
Change your membership to this group:
https://groups.google.com/forum/#!forum/twitter-development-talk