2016-10-02 92 views
0

感謝您的時間,調用PHP谷歌驅動API返回的響應,但不會上傳圖像

我有這樣的代碼:

$googleClient = Google::getClient(); 
$googleClient->setApplicationName("aiesec"); 
$googleClient->setScopes(\Google_Service_Drive::DRIVE); 
//$googleClient->setSubject('[email protected]'); 
$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' 
    ]); 

而且我有這個答案

Google_Service_Drive_DriveFile對象([collection_key:protected] => spaces [appProperties] => [capabilitiesType:protected] => Google_Service_Drive_DriveFileCapabilities [capabilitiesDataType:protected] => [contentHintsType:protected] => Google_Service_Drive_DriveFileContentHints [content HintsDataType:protected] => [createdTime] => [description] => [explicitTrashed] => [fileExtension] => [folderColorRgb] => [fullFileExtension] => [headRevisionId] => [iconLink] => [id] = > 0B5hHgJxzNMhpak5WVlBLa3ZsdUk [imageMediaMetadataType:protected] => Google_Service_Drive_DriveFileImageMediaMetadata [imageMediaMetadataDataType: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:pro [videoMediaMetadataType:protected] => Google_Service_Drive_DriveFileVideoMediaMetadata [videoMediaMetadataDataType:protected] => [=] [size =數組()= [數組]()[數組] [=數組]()[數據類型] => [數據類型] => [數據類型] => [數據類型] => [數據類型] => [數據類型] => [數據類型]處理:保護] =>陣列())

但文件未上傳 ... 我需要做什麼? 感謝您再次一次...

+0

照片是一個變量:$ photo = $ attr ['photo'];而$ attr是發佈的所有數據.. – Stivenson

回答

0

它可能是PHP客戶端(測試版)依然採用V2的API(當我檢查了PHP docs它)。嘗試使用insert而不是create

此外,還詢問similar question有關未添加的內容,並在您將mimeType設置爲application/octet-stream時解決。