Hey,
I'm trying to get file by ID (set into public folder and gave permissions)
File is found, but fields are empty.
Searched for answer, nothing helpful.
this is my simple code:
$client_id = Config::get('google.client_id');
$client_secret = Config::get('google.client_secret');
$key = Config::get('google.api_key');//you can use later
$this->client = new \Google_Client();
$this->client->setClientId($client_id);
$this->client->setClientSecret($client_secret);
$this->client->setDeveloperKey($key);
// $this->client->setScopes(array(
// 'https://www.googleapis.com/auth/drive',
// 'https://www.googleapis.com/auth/drive.file',
// 'https://www.googleapis.com/auth/drive.photos.readonly',
// 'https://www.googleapis.com/auth/drive.metadata',
// 'https://www.googleapis.com/auth/drive.readonly')
// );
$this->service = new \Google_Service_Drive($this->client);
$file_id = '0B3vR4cBcxn4oNm9TSlBzcngyMzQ';
$results = $this->service->files->get($file_id);
dd($results);
Answer is:
Google_Service_Drive_DriveFile {#207 â–¼
#collection_key: "spaces"
+appProperties: null
#capabilitiesType: "Google_Service_Drive_DriveFileCapabilities"
#capabilitiesDataType: ""
#contentHintsType: "Google_Service_Drive_DriveFileContentHints"
#contentHintsDataType: ""
+createdTime: null
+description: null
+explicitlyTrashed: null
+fileExtension: null
+folderColorRgb: null
+fullFileExtension: null
+hasAugmentedPermissions: null
+hasThumbnail: null
+headRevisionId: null
+iconLink: null
+id: "0B3vR4cBcxn4oNm9TSlBzcngyMzQ"
#imageMediaMetadataType: "Google_Service_Drive_DriveFileImageMediaMetadata"
#imageMediaMetadataDataType: ""
+isAppAuthorized: null
+kind: "drive#file"
#lastModifyingUserType: "Google_Service_Drive_User"
#lastModifyingUserDataType: ""
+md5Checksum: null
+mimeType: "image/png"
+modifiedByMe: null
+modifiedByMeTime: null
+modifiedTime: null
+name: "Picture1.png"
+originalFilename: null
+ownedByMe: null
#ownersType: "Google_Service_Drive_User"
#ownersDataType: "array"
+parents: null
#permissionsType: "Google_Service_Drive_Permission"
#permissionsDataType: "array"
+properties: null
+quotaBytesUsed: null
+shared: null
+sharedWithMeTime: null
#sharingUserType: "Google_Service_Drive_User"
#sharingUserDataType: ""
+size: null
+spaces: null
+starred: null
+teamDriveId: null
+thumbnailLink: null
+thumbnailVersion: null
+trashed: null
+trashedTime: null
#trashingUserType: "Google_Service_Drive_User"
#trashingUserDataType: ""
+version: null
#videoMediaMetadataType: "Google_Service_Drive_DriveFileVideoMediaMetadata"
#videoMediaMetadataDataType: ""
+viewedByMe: null
+viewedByMeTime: null
+viewersCanCopyContent: null
+webContentLink: null
+webViewLink: null
+writersCanShare: null
#internal_gapi_mappings: []
#modelData: []
#processed: []
}
Please advise, thanks!
Found it. The problem is in v3. Not showing those values, but getting all data.
Are you sure? Is it not possible to get the downloadUrl parameter?
Hi @o0alexela0o I am facing the same issue. How to get the values of those parameters which the API is returning as null?
I'm experiencing this as well. The getWebViewLink() and getIconLink() methods (among others) return null. Other methods, such as getName(), do return a value. Can anyone shed some light?
EDIT: It just occurred to me that this could be a scoping issue. I'll look into it out and report back.
Does not appear to be an issue with OAuth2 scopes! 😕 Thought sure that was it. Oh well...
@Shotster I had a similar issue when I wanted to fetch content of the google drive file. And then I had to dig deeper into the other drive APIs.
service = GoogleDocs.getDriveService();
Export export = service.files().export(docId, "text/html");
HttpResponse response = export.executeMedia();
This piece of code fetched me the document in the response. And then I parsed the response as a String. Hope this could help you in some way.
Thanks, @rpgayatri. What @o0alexela0o said just sunk in - i.e. that v3 of the Drive REST API just doesn't work like it should. Version 2 of the Drive REST API seems to work, but it apparently isn't supported by the PHP client library. This page directs developers to v3, which is broken. 😕
I understand now that since this problem lies with the REST API and not the library, this issue should remain closed.
FWIW, my work-around was to call the REST API v2 endpoint directly as described in the readme under Making HTTP Requests Directly.
Hello,
I'm new here and i have also experienced this problem and come up with this solution:
$files = $drive->files->listFiles(array(
'q' => "'root' in parents",
'fields' => 'nextPageToken, files(id, name, webViewLink, mimeType)'
))->getFiles();
Add the "webViewLink" in files property.
Hope this helps.
Most helpful comment
Hello,
I'm new here and i have also experienced this problem and come up with this solution:
Add the "webViewLink" in files property.
Hope this helps.