Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将RTF文档转换为Google文档?_Php_Google Api Php Client - Fatal编程技术网

Php 如何将RTF文档转换为Google文档?

Php 如何将RTF文档转换为Google文档?,php,google-api-php-client,Php,Google Api Php Client,我已经有了谷歌的示例代码和我的应用程序创建的RTF文件。如何将此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 fr

我已经有了谷歌的示例代码和我的应用程序创建的RTF文件。如何将此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 boolean  
Whether to convert this file to the corresponding Google Docs format. (Default: false)
可能是这样,但我不确定您的代码是否使用了旧的GoogleAPI PHP客户端库

$createdFile = $service->files->insert($file, array(
      'data' => $data,
      'mimeType' => 'application/rtf',
      'convert' => 'true'

    ));

注意:是的,我知道您正在遵循这个示例,但不幸的是,它使用了旧的客户机库。我听说他们正在更新它。可以在上找到新的Google API PHP客户端库。这里也有一个文件上传的例子,但它非常基本。并且也不包括convert参数

@DalmTo,你说得对。唯一的问题是
'convert'=>true
应该传递一个布尔值,而不是字符串。非常感谢。