Should I expect an array or a dictionary?


#1

Should I expect an array or dictionary when issuing a “GET” to https://api.twitter.com//1.1/statuses/user_timeline.json?count=1&screen_name=xxxx?
I’m currently using Application-only authentication, and successfully returning a bearer token and receiving a json response from twitter. But some requests return NSCFArrays and others return NSCFDictionarys. Shouldn’t it be consistently one or the other?


#2

The API itself returns a JSON array when the request can be served with a result set. There are conditions like rate limiting, a user not being found, or other visibility problems that would result in a HTTP 404, 401, 429, etc – in that case the response would be a JSON hash describing the error. You should monitor HTTP status codes to determine whether the response you got contains the data you’re looking for or not.