0

I get the files from logged in user drive. Need to watch their content

 $this->drive = new Google_Service_Drive($client);

 $optParams = [
    'fields' => 'files(*)',
    'q' => ''
 ];

 $driveContent = $this->drive->files->listFiles($optParams)->getFiles();

foreach ($driveContent as $file) {
      $resuorse =  (new \Google_Service_Drive_Channel());
      $resuorse->setResourceId($file->getID());
      $resuorse->setResourceUri("https://www.googleapis.com/drive/v3/files/".$file->getID());

      dd($this->drive->files->watch($file->getID(), $resuorse));
}

It returns an error

   { "error": { "errors": [ { "domain": "push", "reason": "channelUnknown", "message": "Unknown channel type: " } ], "code": 400, "message": "Unknown channel type: " } }
  • Hello @MG, the `400` error code means that the request type was an incorrect one, more precisely, it seems that the issue is linked to this line of code here `$resuorse = (new \Google_Service_Drive_Channel());`. Moreover, which scopes are you using for your request? Cheers! – ale13 Feb 28 '20 at 11:33
  • I was not able to find a solution for watching file content with this way. Anyway each `$file` object has link to view. It is under `webContentLink` property. Thanks – Marine Gasparyan Mar 01 '20 at 09:41
  • Hello @MG, which scopes are you using? – ale13 Mar 05 '20 at 15:52

1 Answers1

0

You have to set type (web_hook) and set channelId in your request:

$resuorse->setType('web_hook');
$resuorse->setId('some-unique-string');

More info here https://developers.google.com/drive/api/guides/push#required-properties

Viktar Zh
  • 71
  • 1
  • 5