Quickstart: Run a Drive App in PHP
require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_DriveService.php'; $client = new Google_Client(); // Get your credentials from the console $client->setClientId('xxxxxxxxxxxx.apps.googleusercontent.com'); // YOUR_CLIENT_ID $client->setClientSecret('xxxxxxxxxxxxxxxxx-xxxxxxx'); //YOUR_CLIENT_SECRET $client->setRedirectUri('http://localhost/googleapi/quickstart.php'); //urn:ietf:wg:oauth:2.0:oob //urn:ietf:wg:oauth:2.0:oob http://localhost/googleapi/quickstart.php $client->setScopes(array('https://www.googleapis.com/auth/drive')); $service = new Google_DriveService($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_DriveFile(); $file->setTitle('My document4'); $file->setDescription('A test document'); $file->setMimeType('text/plain'); $data = 'this is test';//file_get_contents('document.txt'); $createdFile = $service->files->insert($file, array( 'data' => $data, 'mimeType' => 'text/plain', )); print_r($createdFile);
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。