【发布时间】:2017-10-24 12:51:01
【问题描述】:
没有错误。为什么没有发送文件?
error_reporting(E_ALL);
ini_set('display_errors',1);
try{
require_once './vendor/autoload.php';
$client = new Google_Client();
$oauth_credentials = './vendor/test.json';
$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setScopes('https://www.googleapis.com/auth/drive');
$driveService = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'photo.png'));
$content = file_get_contents('./vendor/plik.png');
$file = $driveService->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'image/png',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);
}catch(Exception $e){
echo $e->getMessage();
}
【问题讨论】:
-
欢迎来到 Stack Overflow。我们不会去其他地方弄清楚你在问什么。所有相关代码都必须在这里,在问题本身中。请参阅 How to Ask 和 minimal reproducible example,然后返回并 edit 您的帖子以包含演示问题所需的最少代码量。您还需要包含用于编写代码的语言的标签,因为这显然是相关的。 (是的,我在标题中看到了 PHP,但它也应该在标签中,以供将来的读者在此处搜索时使用。)
-
请不要在 Stack Overflow 上发布像 paste.ofcode.org 这样的临时内容。
标签: php google-api google-drive-api google-api-php-client