当我从php运行API时,返回的唯一项目是"如何开始使用Drive"文件,该文件不在文件夹中,但是当我从API网页运行retrieveListOfAllFiles()时,我看到驱动器中的所有文件.这是代码.
set_include_path(ABSPATH . "path-to/api/google-api-php-client/src/");
require_once "Google/Client.php";
require_once "Google/Service/Drive.php";
require_once "Google/Auth/OAuth2.php";
require_once "Google/Auth/AssertionCredentials.php";
define('CLIENT_ID', 'xxxxx');
define('SERVICE_ACCOUNT_NAME', 'xxxxx');
$key = file_get_contents(ABSPATH . "path-to-.p12");
$scopes = array('https://www.googleapis.com/auth/drive.readonly');
$client = new Google_Client();
$client->setApplicationName("xxxx");
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$auth = new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
$scopes,
$key
);
$client->setAssertionCredentials($auth);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($auth);
}
$_SESSION['service_token'] = $client->getAccessToken();
$service = new Google_Service_Drive($client);
$files = retrieveAllFiles($service);
Run Code Online (Sandbox Code Playgroud)
文件仅返回"如何开始使用驱动器"文件 - 从此页面进行API测试:https://developers.google.com/drive/v2/reference/files/list返回驱动器中的所有文件.
ID正确,.p12文件是新的和加载,我不知道出了什么问题.
我也注意到,如果我var_dump()的输出
dump($service->files->listFiles(array()));
Run Code Online (Sandbox Code Playgroud)
我也只获得单曲"如何开始使用驱动器"文件.所以,即使我没有收到任何OAuth2错误,并获得密钥令牌等,我想要列出文件的驱动器也没有被访问.
model w/ sample data =>
[{
date: '13413413',
name: 'asdfasdf',
other: 'kjh'
}]
Run Code Online (Sandbox Code Playgroud)
getJSON返回4个数组,每个数组包含10个模型对象.
array1 = 10 of resultsObj sorted by date from newest to oldest
array2 = 10 of resultsObj sorted by date from newest to oldest
array3 = 10 of resultsObj sorted by date from newest to oldest
array4 = 10 of resultsObj sorted by date from newest to oldest
Run Code Online (Sandbox Code Playgroud)
我需要1个数组,所有40个对象按日期排序,最新到最新.
我认为可以通过大量的if/else检查来做到这一点,但是很想看到一些例子/想法,谢谢.