我正在搜索3天,但我还没有成功
我已将Yelp集成到:https://github.com/Pretz/android-example
当我使用我提供的所有凭据运行代码时,我只得到20个结果。我不确定我哪里错了。在下面找到附带的代码
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
Yelp yelp = Yelp.getYelp(YelpSearchActivity.this);
String businesses = yelp.search("shopping", 37.788022, -122.399797);
try {
return processJson(businesses);
} catch (JSONException e) {
return businesses;
}
}
@Override
protected void onPostExecute(String result) {
mSearchResultsText.setText(result);
setProgressBarIndeterminateVisibility(false);
}
}.execute();
String processJson(String jsonStuff) throws JSONException {
JSONObject json = new JSONObject(jsonStuff);
Log.e("return data", ""+json);
JSONArray businesses = json.getJSONArray("businesses");
ArrayList<String> businessNames = new ArrayList<String>(businesses.length());
for (int i = 0; i < businesses.length(); i++) {
JSONObject business = businesses.getJSONObject(i);
businessNames.add(business.getString("name"));
}
return TextUtils.join("\n", businessNames);
}
仅供参考:
// Yelp.getYelp
public static Yelp getYelp(Context context) {
return new Yelp(context.getString(R.string.consumer_key), context.getString(R.string.consumer_secret),
context.getString(R.string.token), context.getString(R.string.token_secret));
}
// yelp.search
public String search(String term, double latitude, double longitude) {
OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.yelp.com/v2/search");
request.addQuerystringParameter("term", term);
request.addQuerystringParameter("ll", latitude + "," + longitude);
this.service.signRequest(this.accessToken, request);
Response response = request.send();
return response.getBody();
}
欢迎任何相关的答案。提前致谢 。
答案 0 :(得分:0)
Yelp的API最多只返回20个结果。你没有做错任何事,他们只是把它限制在20。
Obtaining more than 20 results with Google Places API
但是,似乎有一个way to get up to 60 results。