最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - google drive JS API nextpageToken invalid - Stack Overflow

programmeradmin1浏览0评论

I just followed the API docs and made simple query using JS API and getting an error 400: Invalid Value of the nextPageToken

gapi.load('client', function(){
    gapi.client.load('drive', 'v3', function(){
        gapi.client.init({}
        ).then(function(){
            gapi.client.drive.files.list({
                'q'         : "name contains 'nv'",
                'pageSize'  : 10,
                'fields'    : "nextPageToken, files(id, name, webContentLink, folderColorRgb, thumbnailLink, description)",
                'orderBy'   : 'modifiedTime desc',
            }).then(function(respo){
                var token = respo.result.nextPageToken;
                gapi.client.drive.files.list({
                    'fields' : '*',
                    'pageToken' : token
                }).then(function(result){console.log(result.result);})
            })
        })
    })
}) 

Token returned from first query is ok, getting it full. But in the next query it's bees wrong.

Didn't find a format for the token, so I cannot check if it's good or?!

p.s. tested developers console, getting the token and in the next query getting same error.

I just followed the API docs and made simple query using JS API and getting an error 400: Invalid Value of the nextPageToken

gapi.load('client', function(){
    gapi.client.load('drive', 'v3', function(){
        gapi.client.init({}
        ).then(function(){
            gapi.client.drive.files.list({
                'q'         : "name contains 'nv'",
                'pageSize'  : 10,
                'fields'    : "nextPageToken, files(id, name, webContentLink, folderColorRgb, thumbnailLink, description)",
                'orderBy'   : 'modifiedTime desc',
            }).then(function(respo){
                var token = respo.result.nextPageToken;
                gapi.client.drive.files.list({
                    'fields' : '*',
                    'pageToken' : token
                }).then(function(result){console.log(result.result);})
            })
        })
    })
}) 

Token returned from first query is ok, getting it full. But in the next query it's bees wrong.

Didn't find a format for the token, so I cannot check if it's good or?!

p.s. tested developers console, getting the token and in the next query getting same error.

Share Improve this question asked Nov 20, 2017 at 22:59 aleXelaaleXela 1,3012 gold badges22 silver badges37 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

I have found that the subsequent page request must have the same 'q' value of the first request to avoid getting the HTTP 400 error. For example, if the first request is:

   gapi.client.drive.files.list({
       'q'         : "name contains 'nv'",
       'pageSize'  : 10,
       'fields'    : "nextPageToken, files(id, name)"
   }).then(function(respo){
       ...
   }

The subsequent request must also have the same 'q':

   gapi.client.drive.files.list({
       'q'         : "name contains 'nv'",
       'pageToken' : nextPageToken,
       'pageSize'  : 10,
       'fields'    : "nextPageToken, files(id, name)"
   }).then(function(respo){
       ...
   }

Make sure to always check the validity of nextPageToken as feeding a null value on subsequent request will restart the list operation all over again.

I simply don't believe this!!!

Google makes such stupid things.

The problem is that it needs to be written in next query not pageToken, but nextPageToken and it's working.

Checked couple times, it does.

In docs it's written wrong and also in their console.

Shame!

This is the top result I have found for attempting to do pagination within a Google Drive JavaScript operation. They should just show an example on their documentation, but I could not find it there. Facebook had that example however. Anyway, to do paging in their framework:

//Global variable to hold token pointer
var NextPageToken = '';

function GetFiles() {
   gapi.client.drive.files.list({
     'pageSize': 25,
     'q': "mimeType contains 'image/'",
     'fields': "nextPageToken, files(id, name)"
   }).then(function (response) {
              var files = response.result.files;
              // if response.result.nextPageToken exists, use it
              if (response.result.nextPageToken) {
                 NextPageToken = response.result.nextPageToken;                        
              } else {
                 NextPageToken = false;
              }
           });
    }

function GetNextSetOfImages() {
        gapi.client.drive.files.list({
            'pageSize': 25,
            'q': "mimeType contains 'image/'",
            'pageToken': NextPageToken,
            'fields': "nextPageToken, files(id, name)"
        }).then(function (response) {
              var files = response.result.files;
              // if response.result.nextPageToken exists, use it
              if (response.result.nextPageToken) {
                 NextPageToken = response.result.nextPageToken;                        
              } else {
                 NextPageToken = false;
              }
           });
    }
发布评论

评论列表(0)

  1. 暂无评论