Truncated reply from twitter (statuses/show?id)


#1

Working on iOS app using NSURLSession to perform oauth, and then immediately GET statuses/show.

I am getting Bearer access_token fine. I am also getting reply from statuses/show however the reply data is truncated halfway. No idea why. Here’s an example of the returned data:

<7b226372 65617465 645f6174 223a2257 65642044 65632031 34203038 3a35303a 3234202b 30303030 20323031 36222c22 6964223a 38303839 35373330 30333534 33383739 36382c22 69645f73 7472223a 22383038 39353733 30303335 34333837 39363822 2c227465 7874223a 22236c69 76657370 6c617368 20343820 46726565 20417070 3a687474 70733a5c 2f5c2f74 2e636f5c 2f6c6d49 72744364 5a374820 68747470 733a5c2f 5c2f742e 636f5c2f 71567963 5233645a 5165222c 22747275 6e636174 6564223a 66616c73 652c2265 6e746974 69657322 3a7b2268 61736874 61677322 3a5b7b22 74657874 223a226c 69766573 706c6173 68222c22 696e6469 63657322 3a5b302c 31315d7d 5d2c2273 796d626f 6c73223a 5b5d2c22 75736572 5f6d656e 74696f6e 73223a5b 5d2c2275 726c7322 3a5b7b22 75726c22 3a226874 7470733a 5c2f5c2f 742e636f 5c2f6c6d 49727443 645a3748 222c2265 7870616e 6465645f 75726c22 3a226874 74703a5c 2f5c2f61 70706c65 2e636f5c 2f314a4a 49627a63 222c2264 6973706c 61795f75 726c223a 22617070 6c652e63 6f5c2f31 4a4a4962 7a63222c 22696e64 69636573 223a5b32 342c3437 5d7d5d2c 226d6564 6961223a 5b7b2 <-- it just stops here seems truncated

Help pls.Thank you.


#2

Wow nobody can help? Much community. So Doge.


#3

Well, it is a weekend, and many of us are not working or paying attention to forums when we’re taking time out with our families.

Are you able to convert that payload into something readable in ASCII? I’d expect to see a response in JSON.


#4

Ah yes, weekends… those are nice. I tend to lose track of the day sometimes. Sorry about that. :smiley:

Yes, I was able to convert the data I get into dictionary texts just fine, but that’s just it, the dictionary data also is truncated halfway.

dict {
    contributors = "<null>";
    coordinates = "<null>";
    "created_at" = "Wed Dec 14 08:50:24 +0000 2016";
    entities =     {
        hashtags =         (
                        {
                indices =                 (
                    0,
                    11
                );
                text = livesplash;
            }
        );
        media =         (
                        {
                "display_url" = "pic.twitter.com/qVycR3dZQe";
                "expanded_url" = "https://twitter.com/genecode_/status/808957300354387968/photo/1";
                id = 808957295652524032;
                "id_str" = 808957295652524032;
                indices =                 (
                    48,
                    71
                );
                "media_url" = "http://pbs.twimg.com/tweet_video_thumb/Czn-X9XUUAAm9bh.jpg";
                "media_url_https" = "https://pbs.twimg.com/tweet_video_thumb/Czn-X9XUUAAm9bh.jpg";
                sizes =                 {
                    l <== it stops here.

I checked for the NSURLSession response, status is of course 200 Success. And, the error for NSJSONSerialization method (used to convert the data received into a dictionary data) is also null.

I have tried appending tweet_mode=extended to the URL, still same result too. It looks as though twitter server cut the reply into half. I am not sure why.

The code I wrote to call the API is on this page: http://stackoverflow.com/questions/41199145/twitter-api-json-reply-is-truncated

Thanks.


#5

What is the Tweet ID you’re trying to fetch? If you’re able to share that, i can check whether it works using the raw API using twurl, which would be my first debugging step.

Really odd that this is being truncated. Does it happen with all statuses? Are you able to test with other OAuth contexts? Is this in the simulator, or on a real device?

Unfortunately in my case I’d usually use Fabric’s Twitter Kit to call the API, rather than constructing the calls myself. That would enable statuses/show to be called via the TwitterApiClient object. I’m not directly familiar with the method you’re trying to use here.


#6

I don’t have much experience with objective c but I wanted to see if it was something with that status so I ran it through my PHP library. It returned just fine and the stopping point you’re seeing is at a rather weird spot that couldn’t possibly break syntax. I think for one reason or another you’re only getting a partial response so I decided to google that NSURLSession class you’re using and it seems like this might be what your issues is: http://stackoverflow.com/questions/22987727/ios-trouble-parsing-large-json-message

It sounds like at a certain size, it splits the response into multiple pieces. You would have to get each piece and put them back together before parsing. I believe Twitter has a sdk available for download, might be worth switching to that library.


#7

I suspected something was fishy thanks a lot for the explanation! I might try using delegates instead. If that fail, maybe finally use Fabric as suggested by @andypiper.

Anyway, thanks to both of you for helping out with this problem. Have a nice day!

ps. I’ll update here if my problem is resolved.


#8

Ok just to update:

I tried using delegate of NSURLSession to get the stream data of json reply from twitter. It doesn’t work either. From didReceiveData, both the “response” and “data” were being cut into half. No other way that I know to approach this. I think, there is some missing “fields” in the header of my REST request to twitter but I have no idea what.

I ended up installing Fabric and going to use that for my app. Thanks all. And Merry Christmas! :smiley: