dongshie8450 2015-01-10 19:49
浏览 48

如何使用谷歌驱动器服务检索文件夹

I want to retrieve a folder with Google drive Service. The first problem is that I do not know the folder Id. I only know the folder name that is in my drive.

The second problem is that I only find this snippet of code for downloading file and not folder https://developers.google.com/drive/web/manage-downloads

Here is the beginning of my code, but it does not work :(

session_start();

define( 'GDRIVE_CLIENT_ID', '422321818234bg877v326qtojhcsgsqr6p7fd563jmmh.apps.googleusercontent.com' ); 
define( 'GDRIVE_CLIENT_SECRET', '1V5ADb4CpMZZqdSHfsORWro1' ); 
define( 'GDRIVE_REDIRECT_URIS', 'http://localhost/drive.php' ); 

define( 'GDRIVE_SCOPE_01', 'https://www.googleapis.com/auth/drive' ); 
define( 'GDRIVE_SCOPE_02', 'https://www.googleapis.com/auth/drive.apps.readonly' ); 
define( 'GDRIVE_SCOPE_03', 'https://www.googleapis.com/auth/drive.file' ); 
define( 'GDRIVE_SCOPE_04', 'https://www.googleapis.com/auth/drive.metadata.readonly' ); 
define( 'GDRIVE_SCOPE_05', 'https://www.googleapis.com/auth/drive.readonly' ); 
define( 'GDRIVE_FILE_KEY', 'https://drive.google.com/folderview?id=0B_S8U3a8QeR_cUlCRTBLOWxiUnc&usp=sharing' ); 

$client = new Google_Client(); 
$client->setClientId( GDRIVE_CLIENT_ID ); 
$client->setClientSecret( GDRIVE_CLIENT_SECRET ); 
$client->setRedirectUri( GDRIVE_REDIRECT_URIS ); 
$client->setScopes( array( GDRIVE_SCOPE_01, GDRIVE_SCOPE_02, GDRIVE_SCOPE_03, GDRIVE_SCOPE_04, GDRIVE_SCOPE_05 ) ); 


if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $_SESSION['access_token'] = $client->getAccessToken();
    } else
        $client->setAccessToken($_SESSION['access_token']);

    $service = new Google_Service_Drive($client);
} else {
    $authUrl = $client->createAuthUrl();
    header('Location: ' . $authUrl);
    exit();
}

try { 
  $file = $service->files->get( GDRIVE_FILE_KEY ); 
  echo "Title: ", $file->getTitle(); 
  echo "Description: ", $file->getDescription(); 
  echo "MIME type: ", $file->getMimeType(); 
} catch (Exception $e) { 
  echo "An error occurred: ", $e->getMessage(); 
} 
  • 写回答

1条回答 默认 最新

  • dragam0217 2015-01-11 03:15
    关注

    "The first probleme is that I do not know the folder Id. I only know the folder name that is in my drive."

    Do a files.list with a query containing the file name. See https://developers.google.com/drive/v2/reference/files/list and https://developers.google.com/drive/web/search-parameters

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题