Class 'Google_Service_Docs' not found (Google Docs API quickstart.php)

£可爱£侵袭症+ 提交于 2020-01-16 14:39:42

问题


I am following this guide to authorize access of my website to the Google Docs API but I am having trouble getting through step 4.

When I run this command in the SSH command line as per step 4 the guide:

$ php quickstart.php

nothing happens within the command line, although I have an error log in the working directory and the following appears:

[08-Feb-2019 09:47:23 America/New_York]
PHP Fatal error:  Uncaught Error: Class 'Google_Service_Docs' not found in /home/***/***/composer/quickstart.php:12
Stack trace:
#0 /home/***/***/composer/quickstart.php(62): getClient()
#1 {main}
thrown in /home/***/***/composer/quickstart.php on line 12

For reference, line 12 in the code (which you can view in full in the official Google guide) is line 5 in the code below:

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName('Google Docs API PHP Quickstart');
    $client->setScopes(Google_Service_Docs::DOCUMENTS_READONLY);
    $client->setAuthConfig('credentials.json');
    $client->setAccessType('offline');
...

I have already successfully installed the Sheets API before so there shouldn't be any problem in steps 1 or 2, and step 3 is just copy-paste so I have no idea where the problem could be on my end.


回答1:


There seems to be a problem with the name of the scope. I am trying to find a list of valid scopes for Oath2 of Google APIs but with no success.




回答2:


$client->setScopes(Google_Service_Docs::DOCUMENTS_READONLY);

^ Seems to be obsolete and the guide is not up to date, use this instead:

$client->setScopes(https://www.googleapis.com/auth/documents);


来源:https://stackoverflow.com/questions/54595029/class-google-service-docs-not-found-google-docs-api-quickstart-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!