0
 public class getImagesTask extends AsyncTask<Void, Void, Void>
    {
       JSONObject json;
       ProgressDialog dialog;

       @Override
       protected void onPreExecute() {
           // TODO Auto-generated method stub
           super.onPreExecute();

           dialog = ProgressDialog.show(GoogleSearchAPIExampleActivity.this, "", "Please wait...");
       }

       @Override
       protected Void doInBackground(Void... params) {
           // TODO Auto-generated method stub

           URL url;
           try {
               url = new URL("https://ajax.googleapis.com/ajax/services/search/images?" +"v=1.0&q="+strSearch+"&rsz=8&start=0" );

           URLConnection connection = url.openConnection();
           connection.addRequestProperty("Referer", "http://technotalkative.com");

           String line;
           StringBuilder builder = new StringBuilder();
           BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
           while((line = reader.readLine()) != null) {
               builder.append(line);
           }

           System.out.println("Builder string => "+builder.toString());

           json = new JSONObject(builder.toString());
           } catch (MalformedURLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           return null;
       }

       @Override
       protected void onPostExecute(Void result) {
           // TODO Auto-generated method stub
           super.onPostExecute(result);

           if(dialog.isShowing())
           {
               dialog.dismiss();
           }

           try 
           {
               JSONObject responseObject = json.getJSONObject("responseData");
               JSONArray resultArray = responseObject.getJSONArray("results");

               listImages = getImageList(resultArray);
               Toast.makeText(getBaseContext(), "Length :" + listImages.size(), 5000).show();
              // SetListViewAdapter(listImages);


               System.out.println("Result array length => "+resultArray.length());
               Intent in = new Intent(GoogleSearchAPIExampleActivity.this, Second.class);
               startActivity(in);
           } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

       }
   }

以上是使用 google image api 获取图像的代码。但在这里我只得到 8 张图片进行 1 次搜索。如果我想获得超过 8 个图像,需要做什么?

4

1 回答 1

0

继续我上面的评论,文档状态

rsz    rsz=4    This argument supplies an integer from 1–8 indicating the number of results to return per page.

所以看起来你将不得不用新的电话自己翻阅结果

阅读cursor 这里的使用

于 2013-10-30T19:00:28.940 回答