Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
访问存储在GoogleDrive-PHPAPI中的文件上的文本内容_Php_Api_Google Drive Api - Fatal编程技术网

访问存储在GoogleDrive-PHPAPI中的文件上的文本内容

访问存储在GoogleDrive-PHPAPI中的文件上的文本内容,php,api,google-drive-api,Php,Api,Google Drive Api,我试图获取存储在谷歌硬盘上的文件的文本内容(word和PDF),但经过大量研究后,我无法找到如何使其工作。我使用的是驱动API,所有的认证过程都很好。我可以使用API上传和访问文件 身份验证后,我使用GET代码: $driveService = new Google_Service_Drive($client); $id = ‘XXXX’; $content = $driveService->files->get($id); print_r($content); 我们测试中

我试图获取存储在谷歌硬盘上的文件的文本内容(word和PDF),但经过大量研究后,我无法找到如何使其工作。我使用的是驱动API,所有的认证过程都很好。我可以使用API上传和访问文件

身份验证后,我使用GET代码:

$driveService = new Google_Service_Drive($client);   
$id = ‘XXXX’; 
$content = $driveService->files->get($id);
print_r($content);
我们测试中使用的文件是从API上传的“application/vnd.google apps.document”。 它返回一个包含一些文件信息的对象,但字段“webViewLink”和“webContentLink”为空,我真的不知道为什么? 返回的对象:

Google_Service_Drive_DriveFile Object
(
    [collection_key:protected] => spaces
    [internal_gapi_mappings:protected] => Array
        (
        )

    [appProperties] => 
    [capabilitiesType:protected] => Google_Service_Drive_DriveFileCapabilities
    [capabilitiesDataType:protected] => 
    [contentHintsType:protected] => Google_Service_Drive_DriveFileContentHints
    [contentHintsDataType:protected] => 
    [createdTime] => 
    [description] => 
    [explicitlyTrashed] => 
    [fileExtension] => 
    [folderColorRgb] => 
    [fullFileExtension] => 
    [headRevisionId] => 
    [iconLink] => 
    [id] => XXXX
    [imageMediaMetadataType:protected] => Google_Service_Drive_DriveFileImageMediaMetadata
    [imageMediaMetadataDataType:protected] => 
    [kind] => drive#file
    [lastModifyingUserType:protected] => Google_Service_Drive_User
    [lastModifyingUserDataType:protected] => 
    [md5Checksum] => 
    [mimeType] => application/vnd.google-apps.document
    [modifiedByMeTime] => 
    [modifiedTime] => 
    [name] => 05042016121001_3548
    [originalFilename] => 
    [ownedByMe] => 
    [ownersType:protected] => Google_Service_Drive_User
    [ownersDataType:protected] => array
    [parents] => 
    [permissionsType:protected] => Google_Service_Drive_Permission
    [permissionsDataType:protected] => array
    [properties] => 
    [quotaBytesUsed] => 
    [shared] => 
    [sharedWithMeTime] => 
    [sharingUserType:protected] => Google_Service_Drive_User
    [sharingUserDataType:protected] => 
    [size] => 
    [spaces] => 
    [starred] => 
    [thumbnailLink] => 
    [trashed] => 
    [version] => 
    [videoMediaMetadataType:protected] => Google_Service_Drive_DriveFileVideoMediaMetadata
    [videoMediaMetadataDataType:protected] => 
    [viewedByMe] => 
    [viewedByMeTime] => 
    [viewersCanCopyContent] => 
    [webContentLink] => 
    [webViewLink] => 
    [writersCanShare] => 
    [modelData:protected] => Array
        (
        )

    [processed:protected] => Array
        (
        )

)
我还尝试了另一种方式,使用导出方法。下面是我使用的代码:

$content = $driveService->files->export($id, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', array(
  'alt' => 'media' ));

print_r($content);
它返回一个不同的对象,但我不知道是否可以使用它获取文件内容。以下是返回:

GuzzleHttp\Psr7\Response Object
(
    [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
    [statusCode:GuzzleHttp\Psr7\Response:private] => 200
    [headers:GuzzleHttp\Psr7\Response:private] => Array
        (
            [expires] => Array
                (
                    [0] => Tue, 05 Apr 2016 20:10:33 GMT
                )

            [date] => Array
                (
                    [0] => Tue, 05 Apr 2016 20:10:33 GMT
                )

            [cache-control] => Array
                (
                    [0] => private, max-age=0, must-revalidate, no-transform
                )

            [content-disposition] => Array
                (
                    [0] => attachment
                )

            [vary] => Array
                (
                    [0] => Origin
                    [1] => X-Origin
                )

            [content-type] => Array
                (
                    [0] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
                )

            [x-content-type-options] => Array
                (
                    [0] => nosniff
                )

            [x-frame-options] => Array
                (
                    [0] => SAMEORIGIN
                )

            [x-xss-protection] => Array
                (
                    [0] => 1; mode=block
                )

            [content-length] => Array
                (
                    [0] => 9985
                )

            [server] => Array
                (
                    [0] => GSE
                )

            [alternate-protocol] => Array
                (
                    [0] => 443:quic
                )

            [alt-svc] => Array
                (
                    [0] => quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"
                )

        )

    [headerLines:GuzzleHttp\Psr7\Response:private] => Array
        (
            [Expires] => Array
                (
                    [0] => Tue, 05 Apr 2016 20:10:33 GMT
                )

            [Date] => Array
                (
                    [0] => Tue, 05 Apr 2016 20:10:33 GMT
                )

            [Cache-Control] => Array
                (
                    [0] => private, max-age=0, must-revalidate, no-transform
                )

            [Content-Disposition] => Array
                (
                    [0] => attachment
                )

            [Vary] => Array
                (
                    [0] => Origin
                    [1] => X-Origin
                )

            [Content-Type] => Array
                (
                    [0] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
                )

            [X-Content-Type-Options] => Array
                (
                    [0] => nosniff
                )

            [X-Frame-Options] => Array
                (
                    [0] => SAMEORIGIN
                )

            [X-XSS-Protection] => Array
                (
                    [0] => 1; mode=block
                )

            [Content-Length] => Array
                (
                    [0] => 9985
                )

            [Server] => Array
                (
                    [0] => GSE
                )

            [Alternate-Protocol] => Array
                (
                    [0] => 443:quic
                )

            [Alt-Svc] => Array
                (
                    [0] => quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"
                )

        )

    [protocol:GuzzleHttp\Psr7\Response:private] => 1.1
    [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
        (
            [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #220
            [size:GuzzleHttp\Psr7\Stream:private] => 
            [seekable:GuzzleHttp\Psr7\Stream:private] => 1
            [readable:GuzzleHttp\Psr7\Stream:private] => 1
            [writable:GuzzleHttp\Psr7\Stream:private] => 1
            [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
            [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                (
                )

        )

)
我在网络上做了很多研究,大部分是关于stackoverflow的。我找到了一些信息,但没有找到解决方案。如果有人能在这方面帮助我,我将不胜感激