google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

Can't read docs with multiple tabs

Open amirbabaeii opened this issue 1 year ago • 1 comments

Can't read docs with multiple tabs.

Environment details

  • OS: linux
  • PHP version: 8.3
  • Package name and version: google/apiclient:2.18

Steps to reproduce

  1. create a multiple tab google doc. like this one: image

  2. run the code in code example with your documentID.

Code example

        $client = new Client();
        $service_file = storage_path('google-credentials.json');
        $client->setAuthConfig($service_file);
        $client->setScopes([\Google\Service\Docs::DRIVE, \Google\Service\Docs::DOCUMENTS]);

        $doc_service = new \Google\Service\Docs($client);


        dd($doc_service->documents->get($documentId)->getTabs()); // it returns null

Thanks!

amirbabaeii avatar Dec 12 '24 09:12 amirbabaeii

Can you confirm that the document retrieved by $doc_service->documents->get($documentId) looks as expected other for the lack of tabs?

If so, then there may be an API bug. The next step would be to make the call using the APIs explorer and seeing if tabs is coming back as expected. If so, then it may be an issue with the library. If not then it's an issue with the call you're making, or with the API service itself.

bshaffer avatar Dec 27 '24 20:12 bshaffer

I found out what was the problem. In order to get the tabs, we have to add includeTabsContent parameter to get() function, and set it to true;

here is the correct version:

    $client = new Client();
    $service_file = storage_path('google-credentials.json');
    $client->setAuthConfig($service_file);
    $client->setScopes([\Google\Service\Docs::DRIVE, \Google\Service\Docs::DOCUMENTS]);

    $doc_service = new \Google\Service\Docs($client);

    $document = $doc_service->documents->get($this->documentId, ['includeTabsContent' => true]);

    dd($document ); // it returns the tabs

amirbabaeii avatar Apr 02 '25 10:04 amirbabaeii