2
我已經得到了Google的示例代碼與我的應用程序創建的RTF文件一起工作。如何將此RTF文檔轉換爲Google文檔?如何將RTF文檔轉換爲Google文檔?
<?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('xxxxxx');
$client->setClientSecret('xxxxxx');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$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('5.25.14-M02000-Ramin');
$file->setDescription('A test document');
$file->setMimeType('application/rtf');
$data = file_get_contents('5.25.14-M02000-Ramin.rtf');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'application/rtf',
));
print_r($createdFile);
?>
@達爾姆,你是對的。唯一的是''convert'=> true'應該傳遞一個布爾值而不是一個字符串。謝謝! –