您能告诉我PHP中的此Google Drive API调用函数有什么问题吗? [英] can you tell me what's wrong with this google drive API call function in PHP

查看:95
本文介绍了您能告诉我PHP中的此Google Drive API调用函数有什么问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以运行并从驱动器中获取图像.但是每次运行此代码时,我都会遇到问题.

I've got this code to run and fetch images from my drive. But i'm running into a problem every time I run this code.

  function listF() {

    $result = array();
    $tok = array();
    $nextPageToken = NULL;
  do {
    try {
      $parameters = array();
      if ($nextPageToken) {
        $parameters['pageToken'] = $nextPageToken;
        $parameters['q'] = "mimeType='image/jpeg' or mimeType='image/png'";
      }
      $files = $this->service->files->listFiles($parameters);
      $tok[] = $nextPageToken;
      $result = array_merge($tok, $result, $files->getFiles());
      $nextPageToken = $files->getNextPageToken();
    } catch (Exception $e) {
      print "An error occurred: " . $e->getMessage();
      $nextPageToken = NULL;
    }
  } while ($nextPageToken);
  return $result;
}

我收到此错误:

An error occurred: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "pageToken"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

对我来说,这似乎并不非法.也许您可以找到该错误.谢谢

It doesn't really seem illegitimate to me. Perhaps you might able to find the bug. Thanks

推荐答案

我将使用Javascript回答您的 nextPageToken 问题,只需注意一下逻辑即可.我有两个相同的listFile()函数.一个在初始加载时执行,加载页面后,它显示了我的100个文件中的前10个.另一个在每次单击按钮时执行.

I'll answer your nextPageToken problem using Javascript, just take note of the logic. I have two listFile() functions which are identical. One executes at initial load, after loading the page, it shows the first 10 of my 100 files. The other executes each time a button is clicked.

第一个功能,显示最初的10个文件.

First function to display the inital 10 files.

//take note of this variable
  var nextToken ;
  function listFiles() {
    gapi.client.drive.files.list({
      'pageSize': 10,
      'fields': "*"
    }).then(function(response) {

          //assign the nextPageToken to a variable to be used later
          nextToken = response.result.nextPageToken;
          // do whatever you like here, like display first 10 files in web page
          // . . .
        });
      }

第二功能:通过单击名为下一页"的按钮触发此功能,该按钮显示从11到N的后续文件.

Second function: This function is triggered by click of a button named "Next Page" which displays the succeeding files from 11 to N.

 function gotoNextPage(event) {
          gapi.client.drive.files.list({
            'pageSize': 10,
            'fields': "*",
            'pageToken': nextToken
          }).then(function(response) {
            //assign new nextPageToken to make sure new files are displayed
            nextToken = response.result.nextPageToken;
            //display batch of file results in the web page
            //. . .          
          });
  }

这篇关于您能告诉我PHP中的此Google Drive API调用函数有什么问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆