title: How to load more videos in recycler view using nextPageToken from youtube v3 api json response
body: <p>I am working on one project which requirs to lists all videos from a channel using YouTube data api v3. Everything works fine. I get my first 10 results successfully .but now when user scrolls down and reaches 10th result I want to load next 10 results,</p>
  
  <p>my json response has nextPageToken but i dont know how to use nextPageToken in code to get next page videos in my recycler view, Please help me out .. Thanks in advance ..</p>
  
  <p>json response : </p>
  
  <pre><code>    {
        "nextPageToken": "CAMQAA",
        "pageInfo": {
          "totalResults": 90,
          "resultsPerPage": 3
        },
        "items": [
          {
            "id": "PLqKOsfcZLLdnWQcjBQs_goXt1XUWyyOo91GYUKZyan9g",
            "snippet": {
              "title": "DevBytes: What's new in Android 5.0 Lollipop",
              "description": "Ankur Kotwal introduces the developer highlights of Android 5.0 Lollipop in this DevByte. These are as follows:\n\n00:14 Material Design - http://google.com/design/spec\n00:54 Enhanced Notifications - http://youtu.be/Uiq2kZ2JHVY\n01:56 WebView updates\n02:22 Project Volta - http://youtu.be/KzSKIpJepUw\n03:03 Android Runtime (ART) - http://source.android.com/devices/tech/dalvik/art.html\n03:21 64-bit support - http://d.android.com/tools/sdk/ndk\n03:49 Concurrent documents on Overview\n04:15 Android Work - http://youtu.be/FbVWtYPpzIs\n04:36 Advanced camera capabilities - http://goo.gl/aXXTJ9\n05:05 Game development - http://youtu.be/qW3Ufg1JNRE\n05:45 Connectivity - http://youtu.be/2fZThdNbHcQ\n06:24 What’s next - http://d.android.com/about/versions/android-5.0.html",
      "thumbnails": {
        "medium": {
          "url": "https://i.ytimg.com/vi/um1S2u022HA/mqdefault.jpg",
          "width": 320,
          "height": 180
        },
        "high": {
          "url": "https://i.ytimg.com/vi/um1S2u022HA/hqdefault.jpg",
          "width": 480,
          "height": 360
        }
      },
      "position": 0,
      "resourceId": {
        "videoId": "um1S2u022HA"
      }
    }
  },
  {
    "id": "PLqKOsfcZLLdnWQcjBQs_goeQ8gou_NAnSdPTUnh8ONIE",
    "snippet": {
      "title": "DevBytes: Google Play services 6.1",
      "description": "Learn about Google Play services 6.1 in this DevByte from Magnus Hyttsten. Google Play services 6.1 adds Enhanced Ecommerce analytics support from Google Tag Manager and offers new improvements to the Google Drive Android API. With this release, we're also including a refresh of the Google Fit developer preview, so that you can test your fitness apps on any Android device.",
      "thumbnails": {
        "medium": {
          "url": "https://i.ytimg.com/vi/7E-sqJkrlJ0/mqdefault.jpg",
          "width": 320,
          "height": 180
        },
        "high": {
          "url": "https://i.ytimg.com/vi/7E-sqJkrlJ0/hqdefault.jpg",
          "width": 480,
          "height": 360
        }
      },
      "position": 1,
      "resourceId": {
        "videoId": "7E-sqJkrlJ0"
      }
    }
  },
  {
    "id": "PLqKOsfcZLLdnWQcjBQs_goeKwZG5KaR_D1oPZUTIhFFk",
    "snippet": {
      "title": "DevBytes: Wearable DataLayer API",
      "description": "Wearables are here, and extending your user experience to wear devices is the first step in your wearable strategy. The new DataLayer Apis for Android make it quick and easy to sync events, data, and images between your handheld and wearable device.",
      "thumbnails": {
        "medium": {
          "url": "https://i.ytimg.com/vi/2zReOOEUP18/mqdefault.jpg",
          "width": 320,
          "height": 180
        },
        "high": {
          "url": "https://i.ytimg.com/vi/2zReOOEUP18/hqdefault.jpg",
          "width": 480,
          "height": 360
        }
      },
      "position": 2,
      "resourceId": {
        "videoId": "2zReOOEUP18"
      }
    }
  }
  ]
  }
  </code></pre>
  
  <p>json parsing code :</p>
  
  <pre><code> private ArrayList&lt;VideoData&gt; parseJSONReaponse(JSONObject response) {
  ArrayList&lt;VideoData&gt; listVideos = new ArrayList&lt;&gt;();
  if (response != null || response.length() &gt; 0) {
  
      String nextPageToken = Constants.NA;
      try { 
  
          if (response.has(KEY_NEXTPAGETOKEN)
                  &amp;&amp; !response.isNull(KEY_NEXTPAGETOKEN) ){
              nextPageToken = response.getString(KEY_NEXTPAGETOKEN);
          } 
  
          JSONArray arrayItems = response.getJSONArray(KEY_ITEMS);
  
          for (int i = 0; i &lt; arrayItems.length(); i++) {
              String title = Constants.NA;
              String urlThumbnail = Constants.NA;
              String resourceID = Constants.NA;
  
              JSONObject currentItems = arrayItems.getJSONObject(i);
  
              if (currentItems.has(KEY_SNIPPET)
                      &amp;&amp; !currentItems.isNull(KEY_SNIPPET)) {
                  JSONObject objectSnippet = currentItems.getJSONObject(KEY_SNIPPET);
  
                  if (objectSnippet.has(KEY_TITLE)
                          &amp;&amp; !objectSnippet.isNull(KEY_TITLE)) {
                      title = objectSnippet.getString(KEY_TITLE);
                  } 
  
                  if (objectSnippet.has(KEY_THUMBNAIL)
                          &amp;&amp; !objectSnippet.isNull(KEY_THUMBNAIL)) {
                      JSONObject objectThumbnail = objectSnippet.getJSONObject(KEY_THUMBNAIL);
  
  
                      if (objectThumbnail.has(KEY_THUMBNAIL_MEDIUM)
                              &amp;&amp; !objectThumbnail.isNull(KEY_THUMBNAIL_MEDIUM)) {
                          JSONObject objectThumbnailMedium = objectThumbnail.getJSONObject(KEY_THUMBNAIL_MEDIUM);
  
  
                          if (objectThumbnailMedium.has(KEY_THUMBNAIL_MEDIUM_URL)
                                  &amp;&amp; !objectThumbnailMedium.isNull(KEY_THUMBNAIL_MEDIUM_URL)) {
                              urlThumbnail = objectThumbnailMedium.getString(KEY_THUMBNAIL_MEDIUM_URL);
                          } 
                      } 
                  } 
  
                  if (objectSnippet.has(KEY_RESOURCEID)
                          &amp;&amp; !objectSnippet.isNull(KEY_RESOURCEID)) {
                      JSONObject objectResourceId = objectSnippet.getJSONObject(KEY_RESOURCEID);
  
                      if (objectResourceId.has(KEY_VIDEOID)
                              &amp;&amp; !objectResourceId.isNull(KEY_VIDEOID)) {
                          resourceID = objectResourceId.getString(KEY_VIDEOID);
                      } 
                  } 
              } 
  
              VideoData videoData = new VideoData();
              videoData.setTitle(title);
              videoData.setUrlThumbnail(urlThumbnail);
              videoData.setVideoId(resourceID);
  
              if (!title.equals(Constants.NA)){
                  listVideos.add(videoData);
              } 
  
          } 
  
      } catch (JSONException e) {
          e.printStackTrace();
      } 
  } 
  return listVideos;
  } 
  </code></pre>