Google API 2.0 PHP服务器到服务器无法将文件上载到Google驱动器
我正在尝试使用谷歌API 2.0(PHP版本)将图像从我的网站上传到我的谷歌硬盘。当我尝试下面的代码时,网页上没有报告错误,但我的照片没有上传。有人能帮我解决这个问题吗?我知道这件事。Google API 2.0 PHP服务器到服务器无法将文件上载到Google驱动器,php,drive,Php,Drive,我正在尝试使用谷歌API 2.0(PHP版本)将图像从我的网站上传到我的谷歌硬盘。当我尝试下面的代码时,网页上没有报告错误,但我的照片没有上传。有人能帮我解决这个问题吗?我知道这件事。 require_once realpath('vendor/autoload.php'); $client = new Google_Client(); $client->setAuthConfig('vendor/MyProject.json'); $client->useApplicationD
require_once realpath('vendor/autoload.php');
$client = new Google_Client();
$client->setAuthConfig('vendor/MyProject.json');
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);
// This is uploading a file directly, with no metadata associated.
$file = new Google_Service_Drive_DriveFile();
$result = $service->files->create(
$file,
array(
'data' => file_get_contents('1.jpeg'),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
)
);
?>