javascript - google drive JS API nextpageToken invalid - Stack Overflow

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

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;
              }
           });
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745174258a4615113.html

相关推荐

  • javascript - google drive JS API nextpageToken invalid - Stack Overflow

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

    1小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信