Google Scripts + Google API PHP

时间:2015-06-08 16:50:09

标签: php google-apps-script google-api google-apps google-api-php-client

我正试图从我的google-api-php-client调用我的一个Google脚本,但我找不到如何执行此操作。

我将我的应用程序部署为网络应用程序,并且我获得了可以使用curl调用的网络应用程序网址,但我需要将其称为“谷歌客户端”。

我在驱动器服务中找到了一个应用程序列表,但我无法弄清楚如何找到哪个应用程序是正确的以及如何调用它。我甚至不知道首先检查是否正确,因为我没有从文档中找到任何内容。

    $googleDrive = new \Google_Service_Drive($this->_googleClient);
    $test = $googleDrive->apps->listApps();
    var_dump($test);

无论如何,如果我收到应用程序,它只会返回一个Google_Service_Drive_App实例,但内部没有任何内容可以用我的帖子参数调用脚本。

更新

我正在使用适用于PHP的Google API客户端库

https://developers.google.com/api-client-library/php/start/get_started https://developers.google.com/api-client-library/php/start/installation

用户通过oAuth使用\ Google_Client()进行身份验证;使用所有DRIVE范围进行许可。

我的Google脚本位于用户驱动器内部,我正在尝试远程执行它。我将脚本部署为Web应用程序。您可以在下面找到脚本文件网址。

https://script.google.com/macros/s/[my_google_script_id]/exec

基本上我希望用于PHP的Google API客户端库从用户驱动器执行脚本文件。

我尝试直接使用Google_Http_Request类并使用Google_Client执行它,它几乎按预期工作。

    $googleRequest = new \Google_Http_Request($url, 'POST', null, array('post' => 'parameters'));
    $this->_googleClient->execute($googleRequest);

1 个答案:

答案 0 :(得分:1)

我最终使用CURL请求直接传递带有token_type和access_token的“Authorization”标头,并且它按预期工作。我没有找到任何方法使用Google API Client Library for PHP

    POST
    Authorization: Bearer [your_auth_token]
    Content-Length: 0