Get file name from id with Google Drive PHP Libraray

  Kiến thức lập trình

I’m using the Google PHP Library with a service account. I’m trying to get the name of a doc in a shared team drive by using the doc ID. The service account is a content manager on the shared drive. The code below results in code 404, File not found.

PHP Code

$client = new Google_Client();
$client->setApplicationName('Google API Test');
$client->setScopes([Google_Service_Drive::DRIVE]);
$client->setAccessType('offline');
$client->setAuthConfig('credentials.json);

$service = new Google_Service_Drive($client); 

$files = $service->files->get('xxxxxxxxxxxxxxxxxxxxxxxxxxx');

echo "File Name: " . $file->getName();

Full Error Message

PHP Fatal error:  Uncaught GoogleServiceException: {
  "error": {
    "code": 404,
    "message": "File not found: xxxxxxxxxxxxxxxxxxxxxxxxxxx.",
    "errors": [
      {
        "message": "File not found: xxxxxxxxxxxxxxxxxxxxxxxxxxx.",
        "domain": "global",
        "reason": "notFound",
        "location": "fileId",
        "locationType": "parameter"
      }
    ]
  }
}

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT