本文介绍了谷歌驱动JS API nextpageToken无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是遵循API文档,并使用JS API
进行简单查询并获得错误400: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);})
})
})
})
})

从第一个查询返回的令牌是可以的,将它填满。
但是在下一个查询中,它变成了错误。

没有找到令牌的格式,所以我无法检查它是好还是?! p>

ps测试开发者控制台,获取令牌,并在下一个查询中得到相同的错误。

试图在Google云端硬盘JavaScript操作中进行分页。他们应该在他们的文档上显示一个例子,但我在那里找不到它。然而Facebook有这样的例子。无论如何,要在他们的框架中进行分页:

$ $ p $ //全局变量保存令牌指针
var NextPageToken ='' ;

函数GetFiles(){
gapi.client.drive.files.list({$ b $'pageSize':25,
'q':mimeType contains' image /',
'fields':nextPageToken,files(id,name)
})。then(function(response){
var files = response.result.files;
//如果存在response.result.nextPageToken,则使用它
if(response.result.nextPageToken){
NextPageToken = response.result.nextPageToken;
} else {
NextPageToken = false;
}
});


函数GetNextSetOfImages(){
gapi.client.drive.files.list({$ b $'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;
}
});
}


I just followed the API docs and made simple query using JS APIand 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 becomes 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.

解决方案

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

这篇关于谷歌驱动JS API nextpageToken无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 01:31