使用PHP调用的Google驱动程序API返回响应,但不上传图像


Google driver API called with PHP returns a response but does not upload image

感谢您的宝贵时间,

我有这样的代码:

$googleClient = Google::getClient();
$googleClient->setApplicationName("aiesec");
$googleClient->setScopes('Google_Service_Drive::DRIVE);
//$googleClient->setSubject('stivenson.rpm@gmail.com');
$googleClient->setAuthConfig('/opt/lampp/htdocs/aiesec/administration/aiesec-34835b27733e.json');

$service = new 'Google_Service_Drive($googleClient);

$himage = new Image; // only is helper class 
$file = new 'Google_Service_Drive_DriveFile();
$file->setName($attr['names'].' '.$attr['last_names']);
$file->setDescription('Foto de '.$attr['names'].' '.$attr['last_names'].' desde App');
$file->setMimeType('image/'.$himage->getMime($photo));

$createdFile = $service->files->create($file, [
      'data' => file_get_contents($himage->getPath($photo)),
      'mimeType' => 'image/'.$himage->getMime($photo),
      'uploadType' => 'multipart'
    ]);

And I Have this answer

Google_Service_Drive_DriveFile对象([collection_key:保护]=>空间[appProperties] => [capabilitiesType:保护]=> Google_Service_Drive_DriveFileCapabilities [capabilitiesDataType:保护]=> [contentHintsType:保护]=> Google_Service_Drive_DriveFileContentHints [contentHintsDataType:保护]=> [createdTime] =>[描述]=> [explicitlyTrashed] => [fileExtension] => [folderColorRgb] => [fullFileExtension] => [headRevisionId] => [iconLink] => [id] =>0b5hhgjxnmhpak5wvlbla3zsduk [imagemediametadatype:protected] => google_service_drive_drivefileimagemediametatype:protected] => [isAppAuthorized] => [kind] => drive#file [lastModifyingUserType:protected] => Google_Service_Drive_User [lastModifyingUserDataType:protected] => [md5Checksum] => [mimeType] => image/jpeg [modifiedByMeTime] => [modifiedTime] => [name] => Stivenson Rincon Mora [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] => [trashed] => [version] => [videoMediaMetadataType:protected] =>Google_Service_Drive_DriveFileVideoMediaMetadata [videoMediaMetadataDataType:protected] => [viewedByMe] => [viewedByMeTime] => [viewersCanCopyContent] => [webContentLink] => [webViewLink] => [writersCanShare] => [internal_gapi_mappings:protected] => Array () [modelData:protected] => Array () [processed:protected] => Array ())

但是文件没有上传我需要什么?

可能PHP客户端(beta)仍在使用v2 api(当我检查PHP文档时)。试着用insert代替create

另外,当您将mimeType设置为application/octet-stream时,也会询问未添加的内容,并解决了类似的问题。