我一直在尝试使用Foursquare API构建Android应用。我希望我的用户是匿名的,这样就不会有身份验证。如上所述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.
我发现Venue类别(“https://api.foursquare.com/v2/venues/categories”)是Venues Platform端点,因此我获取了这样的类别:
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");
我得到java.io.FileNotFoundException:https://api.foursquare.com/v2/venues/categories
我还是首先需要在这里获取访问令牌吗?
答案 0 :(得分:2)
您是对的,您无需身份验证即可访问venues/categories
端点,但为了实现此目的,您需要提供客户端ID和客户端密钥作为API调用的参数,以便Foursquare知道它是您的应用访问端点。
您可以注册一个应用程序来获取客户端ID和密钥here(如果您还没有),那么如果您将详细信息添加到网址,您应该能够访问该端点:
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);
希望有所帮助。