繁体   English   中英

PHP - 使用Google Drive API上传时出现问题

[英]PHP - Problems uploading with Google Drive API

我正在尝试使用以下PHP代码使用de Google Drive API上传文件:

<?php

require_once 'src/Google/Client.php';
require_once 'src/contrib/Google_DriveService.php';
require_once __DIR__.'/vendor/autoload.php';


$client_id = 'YOUR CLIENT ID';
$client_secret = 'YOUR CLIENT SECRET';
$redirect_uri = 'http://localhost/modeloImpacto.php';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
//$client->addScope("https://www.googleapis.com/auth/drive");
 $client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_Service_Drive($client);

$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'funcionou.jpg'));
$content = file_get_contents('funcionou.jpg');
$file = $driveService->files->create($fileMetadata, array(
  'data' => $content,
  'mimeType' => 'image/jpeg',
  'uploadType' => 'multipart',
  'fields' => 'id'));
printf("File ID: %s\n", $file->id);

?>

但是我遇到以下错误:

Fatal error: Class 'Google_ServiceResource' not found in C:\wamp64\www\src\contrib\Google_DriveService.php on line 25

有人知道我做错了什么吗?

谢谢! Raffael Siqueira。

尝试按照PHP快速入门中的步骤操作:

  • 第1步:打开Drive API
  • 第2步:安装Google客户端库
  • 第3步:设置样本
  • 第4步:运行样本

此外,如果有任何可能影响您的应用的更新,最好查看Google API客户端升级指南

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM