返回文件夹ID,但不创建文件夹

编程入门 行业动态 更新时间:2024-10-13 14:21:31
本文介绍了返回文件夹ID,但不创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用下面的代码

define('DRIVE_SCOPE', 'www.googleapis/auth/drive'); define('SERVICE_ACCOUNT_EMAIL', 'xxx.iam.gserviceaccount'); define('SERVICE_ACCOUNT_PKCS12_FILE_PATH', 'xxx'); function buildService($userEmail) { $key = file_get_contents(SERVICE_ACCOUNT_PKCS12_FILE_PATH); $auth = new Google_Auth_AssertionCredentials( SERVICE_ACCOUNT_EMAIL, array(DRIVE_SCOPE), $key); //$auth->sub = $userEmail; $client = new Google_Client(); $client->setAssertionCredentials($auth); return new Google_Service_Drive($client); } $service = buildService('xxx.apps.googleusercontent'); $fileMetadata = new Google_Service_Drive_DriveFile(array( 'name' => 'Invoices', 'mimeType' => 'application/vnd.google-apps.folder' )); $file = $service->files->create($fileMetadata, array( 'fields' => 'id' )); printf("Folder ID: %s\n", $file->id);

我一直试图通过PHP在我的驱动器帐户上创建一个文件夹.我相信所有配置都正确,并且得到了结果

I have been trying to create a folder on my drive account through PHP. I believe everything is configured correctly and I am getting a result

文件夹ID:0B2nllBpB_k0NQWFNUjlSc0NUdE0

Folder ID: 0B2nllBpB_k0NQWFNUjlSc0NUdE0

但是没有在我的驱动器帐户上创建该文件夹.创建文件也是如此.它不断返回ID,但实际上未创建任何内容.我到底在做错什么?

But the folder is not being created on my drive account. The same goes with creating files as well. It keeps returning an ID but nothing is actually created. What exactly am I doing wrong?

推荐答案

您当前的代码正在作为服务帐户进行身份验证并正在创建文件.这样,生成的文件将只能由服务帐户访问,而不能由您的Google用户访问.您可以通过执行文件列表而不是代码中的创建来确认这一点,您将取回先前创建的文件.

Your current code is authenticating as the service account and creating a file. The resultant file would then only be accessible to the service account, not your Google user. You can confirm this by doing a list of files instead of a create in your code, you'll get back the files you've previously created.

您的代码已将sub =注释掉.取消注释该行,并确保您已按照域范围内的授权说明进行操作,因此您的代码可以进行身份​​验证并充当您的Google用户.

Your code has sub= commented out. Uncommented that line and make sure you've followed the domain-wide delegation instructions so that your code can authenticate and act as your Google user.

更多推荐

返回文件夹ID,但不创建文件夹

本文发布于:2023-11-28 15:08:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   但不   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!