简体   繁体   中英

Foursquare api request returns error code 200 sometimes

I am using the following code to request the Foursquare venues/explore endpoint for nearby locations:

NSString *key = searchBox.text ? [searchBox.text stringByReplacingOccurrencesOfString:@" " withString:@"%20"] : @"";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYYMMdd"];
NSString* date = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:[NSDate date]]];

[dateFormatter release];

NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?ll=%f,%f&query=%@&radius=50000&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=%@", myMapView.userLocation.location.coordinate.latitude, myMapView.userLocation.location.coordinate.longitude, key, date];

Most of the times, it returns results as expected, but other times, it returns the error code 200 . From the docs I can see it means that I am using a deprecated value. I do not understand, if the date I am passing is causing the problems. I tried to find out if it needs a specific version, or the current date. What am I doing wrong here?

The date you pass in to the v param should be a fixed date greater than 20120609 . This is the "version" of the API response you want and your application is capable of parsing. It's a little unexpected that the 200 deprecated only sometimes comes back—it should always come back if you're passing in a v param less than 20120609 .

Foursquare occasionally changes the JSON format of its responses and the v param is a tool for you to safeguard against these changes. (To see an example, make a request with 20110101 and 20140101 and notice the change in structure). You should periodically update this fixed date and check to see if anything has broken. For more information, see the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM