기본적으로 Google 개발자의 설명서는 API의 새 버전과 일치하도록 업데이트되지 않습니다. 여기 Google 드라이브 PHP api, 드라이브에 파일 삽입
내 코드입니다 :<?php
require_once 'autoload.php';
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId ('CLIENT_ID');
$client->setClientSecret ('CLIENT_SECRET');
$client->setRedirectUri ('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes (array (
'https://www.googleapis.com/auth/drive'
));
$service = new Google_Service ($client);
$authUrl = $client->createAuthUrl();
// Request authorization
print "Please visit:\n$authUrl\n\n";
print "Please enter the auth code:\n";
$authCode = trim (fgets (STDIN));
// Exchange authorization code for access token
$accessToken = $client->authenticate ($authCode);
$client->setAccessToken ($accessToken);
// Insert a file
$file = new Google_Service_Drive_DriveFile();
$file->setTitle ('My document');
$file->setDescription ('A test document');
$file->setMimeType ('text/plain');
$data = file_get_contents ('document.txt');
$createdFile = $service->files->insert ($file, array (
'data' => $data,
'mimeType' => 'text/plain'
));
echo $createdFile;
?>
그리고 이것은 내가 오류입니다 :
PHP Notice: Undefined property: Google_Service::$files in D:\DATA\java\php workspace\Google Drive api test\quickstart.php on line 34
PHP Fatal error: Call to a member function insert() on a non-object in D:\DATA\java\php workspace\Google Drive api test\quickstart.php on line 34
이 코드의 문제가있는 라인 : 당신은 어떤이있는 경우
$createdFile = $service->files->insert
만약 내가 다른 수업을 들여와야한다고 생각하거나 조언을 해주십시오. 고맙습니다.