谷歌驱动器文件上传并将其共享给公共访问

时间:2014-05-11 22:38:15

标签: php file-upload google-drive-api public google-api-php-client

我正在将文件上传到Google云端硬盘帐户,我想做的是让它可读,但不能向公众编辑。我怎么能这样做?

$file = new Google_Service_Drive_DriveFile();
$file->title = $_POST['name'];
$file->shared = "public"; //i need to do this
$file->folder = "/somefolder/"; // and this

[可选]

这实际上是三合一问题:我还想将该文件放入驱动器上的特定文件夹中,我想知道如何在google驱动器上创建该文件夹。

1 个答案:

答案 0 :(得分:0)

可能对新手有用:


free(lastname); 
free(name); 

第1步:

  1. 创建文件夹。 API将返回创建的文件夹的ID。

第2步:

使用CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender)); CREATE TABLE People ( ID INT, name VARCHAR(50), gender CHAR(1), height FLOAT, PRIMARY KEY (ID), FOREIGN KEY (gender) REFERENCES Gender (gender)); CREATE TABLE Sports ( ID INT, name VARCHAR(50), record FLOAT, PRIMARY KEY (ID), UNIQUE (name)); CREATE TABLE Competitions ( ID INT, place VARCHAR(50), held DATE, PRIMARY KEY (ID)); CREATE TABLE Results ( peopleID INT NOT NULL, competitionID INT NOT NULL, sportID INT NOT NULL, result FLOAT, PRIMARY KEY (peopleID, competitionID, sportID), FOREIGN KEY (peopleID) REFERENCES People (ID), FOREIGN KEY (competitionID) REFERENCES Competitions (ID), FOREIGN KEY (sportID) REFERENCES Sports (ID)); 将文件上传到文件夹中

示例:

<?php
$client = new Google_Client();

// SET Client ID, Client Secret, Tokens as per your mechanism
?>

第3步:

将权限设置为可共享:

setParents([]);

参考:https://developers.google.com/drive/api/v3/reference/permissions/create