本文介绍了PHP谷歌驱动器文件列表不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php 

require_once'./src/Google_Client.php';
require_once'./src/contrib/Google_DriveService.php';
$ client = new Google_Client();
$ client-> setApplicationName(test);
$ client-> setClientId('test.apps.googleusercontent.com');
$ client-> setClientSecret('test');
$ client-> setRedirectUri('http://test.com/');
$ client-> setScopes(array('https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/drive.readonly','https: //www.googleapis.com/auth/drive.file','https://www.googleapis.com/auth/drive.metadata.readonly','https://www.googleapis.com/auth/drive。应用程序数据, '的https://www.googleapis.com/auth/drive.apps.readonly'));

if(empty($ _ GET ['code']))
{
$ client-> authenticate();
}


$ service = new Google_DriveService($ client);
$ client-> setAccessToken($ accessToken);
$ accessToken = $ client-> authenticate($ _ GET ['code']);


$ response = http_get(https://www.googleapis.com/drive/v2/files?q=mimeType+%3D+'audio%2Fmpeg'&fields=items(标题%2CwebContentLink)及关键= $的accessToken)。
print_r($ response);


?>

此GET文件列表无效。

我怎样才能得到像那样的文件列表? mimetype:audio / mpeg和fields获得title和webcontentlink。

解决方案

为什么要构建GET请求?您应该



我不是100%确定如何结合doc,但不是像你一样直接构建查询,你应该试图利用这个库。


<?php

require_once './src/Google_Client.php';
require_once './src/contrib/Google_DriveService.php';
$client = new Google_Client();
$client->setApplicationName("test");
$client->setClientId('test.apps.googleusercontent.com');
$client->setClientSecret('test');
$client->setRedirectUri('http://test.com/');
$client->setScopes(array('https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/drive.readonly','https://www.googleapis.com/auth/drive.file','https://www.googleapis.com/auth/drive.metadata.readonly','https://www.googleapis.com/auth/drive.appdata','https://www.googleapis.com/auth/drive.apps.readonly'));

if(empty($_GET['code']))
{
    $client->authenticate();
}


$service = new Google_DriveService($client);
$client->setAccessToken($accessToken);
$accessToken = $client->authenticate($_GET['code']);


    $response = http_get("https://www.googleapis.com/drive/v2/files?q=mimeType+%3D+'audio%2Fmpeg'&fields=items(title%2CwebContentLink)&key=".$accessToken);
    print_r($response);


?>

this GET files list doesn't work.

how can i get files list like that? mimetype : audio/mpeg and fields get title and webcontentlink.

解决方案

Why are you building a GET request? You should be using the API to list files

I'm not 100% sure how to go about incorporating the information from the "Search for Files" doc, but rather than building that query directly like you are, you should be attempting to leverage the library.

这篇关于PHP谷歌驱动器文件列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 00:54