2011-12-06 9 views
0

私はFoursquare APIでAndroidアプリを構築しようとしています。ユーザーが匿名になり、認証がないようにしたい。FourSquareから会場カテゴリを取得するときのjava.io.FileNotFoundException

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"); 
:私は、私はこのようなカテゴリをフェッチして会場カテゴリー(「https://api.foursquare.com/v2/venues/categories」)会場プラットフォームのエンドポイントです見つけ

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. 

here述べたように

java.io.FileNotFoundException:https://api.foursquare.com/v2/venues/categoriesとなります。
ここで最初にアクセストークンを取得する必要はありますか?

答えて

2

あなたは正しいですが、認証なしでvenues/categoriesエンドポイントにアクセスできますが、これを行うにはクライアントIDとクライアントシークレットをAPIコールのパラメータとして指定する必要があります。そのためFoursquareはアプリケーションがエンドポイントにアクセスしていることを認識します。

あなたはURLに詳細を追加した場合、その後、あなたはエンドポイントにアクセスできるようにする必要があり、(お持ちでない場合)クライアント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); 

希望に役立ちます。

+0

thx、それは動作します!ところで、Foursquare APIを使って匿名のLBSを構築することは実現可能だと思いますか?私は認証の有無にかかわらず、匿名性を行うことができます。 – manuzhang

関連する問題