Reputation: 3025
I've been trying to build an Android app on with Foursquare API. I want my users to be anonymous so that there will be no authentication. As stated here:
As covered in our platform docs, our Venues Platform endpoints can be accessed without
user authentication and our Merchant Platform endpoints require the end-user to be an
authed venue manager. All other endpoints, unless otherwise noted, require user
authentication.
I found Venue Categories ("https://api.foursquare.com/v2/venues/categories") are Venues Platform endpoints so I fetched the categories like this:
private static final String API_URL = "https://api.foursquare.com/v2";
private static final String VENUE_CATEGORY = "/venues/categories";
URL url = new URL(API_URL + VENUE_CATEGORY);
Log.d(TAG, "Opening URL " + url.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.connect();
String response = streamToString(urlConnection.getInputStream());
JSONObject jsonObj = (JSONObject) new JSONTokener(response).nextValue();
JSONObject resp = (JSONObject) jsonObj.get("response");
JSONArray category = resp.getJSONArray("categories");
JSONObject sample = category.getJSONObject(0);
mCategoryName = sample.getString("name");
And I get java.io.FileNotFoundException:https://api.foursquare.com/v2/venues/categories
.
Do I still firstly need to fetch access token here?
Upvotes: 0
Views: 1339
Reputation: 496
You are right, you can access the venues/categories
endpoint without authentication but in order to do this you need to supply your Client ID and Client Secret as parameters to the API call, so that Foursquare knows it is your app accessing the endpoint.
You can register an app to get a Client ID and Secret here (if you haven't already), then if you add the details to the url, you should be able to access the endpoint:
private static final String API_URL = "https://api.foursquare.com/v2";
private static final String VENUE_CATEGORY = "/venues/categories";
private static final String CLIENT_INFO = "client_id=YOURCLIENTID&client_secret=YOURCLIENTSECRET"
URL url = new URL(API_URL + VENUE_CATEGORY + "?" + CLIENT_INFO);
Hope that helps.
Upvotes: 2