2015-11-02 76 views
0

我目前正在研究社交媒體應用程序,我想要獲取所有Instagram圖片提要。我現在用的是londatiga庫,到目前爲止,我只得到了10的飼料,我想所有的,我使用的代碼是:使用londatiga圖書館獲取所有Instagram資訊提供

public class DownloadTask extends AsyncTask<URL, Integer, Long> { 

    protected void onCancelled() { 
    } 

    protected void onPreExecute() { 
     pDialog = new ProgressDialog(getActivity()); 
     pDialog.setMessage("Getting Feeds..."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(false); 
     pDialog.show(); 
    } 

    protected Long doInBackground(URL... urls) { 
     long result = 0; 

     try { 
      List<NameValuePair> params = new ArrayList<NameValuePair>(1); 

      params.add(new BasicNameValuePair("count", "10")); 

      InstagramRequest request = new InstagramRequest(
        mInstagramSession.getAccessToken()); 
      String response = request.createRequest("GET", 
        "https://stackoverflow.com/users/self/feed", params); 

      if (!response.equals("")) { 
       JSONObject jsonObj = (JSONObject) new JSONTokener(response) 
         .nextValue(); 
       JSONArray jsonData = jsonObj.getJSONArray("data"); 

       int length = jsonData.length(); 
       flag_loading = false; 

       if (length > 0) { 

        for (int i = 0; i < length; i++) { 
         JSONObject jsonPhoto = jsonData.getJSONObject(i) 
           .getJSONObject("images") 
           .getJSONObject("low_resolution"); 
         mPhotoList.add(jsonPhoto.getString("url")); 
        } 
       } 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return result; 
    } 

    protected void onProgressUpdate(Integer... progress) { 
    } 

    protected void onPostExecute(Long result) { 
     pDialog.dismiss(); 
     adapter.notifyDataSetChanged(); 
    } 
} 

回答

0
private LinkedList<String> mPhotoList = new LinkedList<String>(); 
    private LinkedList<String> mPhotoListIds = new LinkedList<String>(); 

    private static String nextMaxId = ""; 
    private static String url = ""; 

    //onCreateView 


     listView.setOnScrollListener(new AbsListView.OnScrollListener() { 
      @Override 
      public void onScrollStateChanged(AbsListView view, int scrollState) { 

      } 

      @Override 
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 
       if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount != 0) { 
        if (flag_loading == false) { 
         flag_loading = true; 
         new DownloadTask(true).execute(); 
        } 
       } 
      } 
     }); 
     if (mInstagramSession.isActive()) { 
      new DownloadTask(false).execute(); 
     } 





    ProgressDialog pDialog; 

    public class DownloadTask extends AsyncTask<URL, Integer, Long> { 

     private boolean isBeingPaginated = false; 

     public DownloadTask(boolean isBeingPaginated) { 
      this.isBeingPaginated = isBeingPaginated; 
     } 

     protected void onCancelled() { 

     } 

     protected void onPreExecute() { 
      pDialog = new ProgressDialog(getActivity()); 
      pDialog.setMessage("Getting Feeds..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 

     protected Long doInBackground(URL... urls) { 
      long result = 0; 


      try { 
       List<NameValuePair> params = new ArrayList<>(1); 
       params.add(new BasicNameValuePair("count", "10")); 


       if (isBeingPaginated) { 
        url = "https://api.instagram.com/v1/tags/self/media/recent?access_token=" + mInstagramSession.getAccessToken() + "&max_id=" + nextMaxId; 

        params.add(new BasicNameValuePair("next_url", url)); 
       } 

       InstagramRequest request = new InstagramRequest(
         mInstagramSession.getAccessToken()); 
       String response = request.createRequest("GET", 
         "https://stackoverflow.com/users/self/feed", params); 

       if (!response.equals("")) { 
        JSONObject jsonObj = (JSONObject) new JSONTokener(response) 
          .nextValue(); 
        JSONArray jsonData = jsonObj.getJSONArray("data"); 
        JSONObject jsonPaginatioNData = jsonObj.getJSONObject("pagination"); 

        //Fetching nextMaxId 
        if (jsonPaginatioNData.length() > 0) { 
         //JSONObject paginationJsonObject = jsonPaginatioNData.getJSONObject(0); 
         nextMaxId = jsonPaginatioNData.getString("next_max_id"); 
         Log.d("max", nextMaxId); 
         isBeingPaginated = true; 

        } 

        int length = jsonData.length(); 
        flag_loading = false; 

        if (length > 0) { 

         for (int i = 0; i < length; i++) { 
          JSONObject jsonPhoto = jsonData.getJSONObject(i) 
            .getJSONObject("images") 
            .getJSONObject("low_resolution"); 
          JSONObject jsonUser = jsonData.getJSONObject(i) 
            .getJSONObject("users_in_photo") 
            .getJSONObject("user"); 

          String jsonPhotoIds = jsonData.getJSONObject(i) 
            .getString("id"); 
          String jsonPhotoIds = jsonData.getJSONObject(i) 
            .getString("id"); 
          Log.d("ID: ", jsonPhotoIds); 

          mPhotoList.addjsonPhoto.getString("url") 
          mPhotoListIds.add(jsonPhotoIds); 
         } 
        } 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

      return result; 
     } 

     protected void onProgressUpdate(Integer... progress) { 
     } 

     protected void onPostExecute(Long result) { 
      pDialog.dismiss(); 
      adapter.notifyDataSetChanged(); 
     } 
    } 

} 

這是我做過什麼,現在我得到新列表視圖滾動