Google Scripts + Google API PHP

1k views Asked by At

I am trying to call one of my Google Scripts from my google-api-php-client and I can't find how to do this.

I deployed my app as a web app, and I got the web app url which I can call with curl, but I need to call it as my "google client".

I've found a list of apps inside my drive service, but I can't figure out how to find which app is the proper one and how to call it. I don't even know if it's the right thing to check first as I don't find anything from the documentation.

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

And anyway if I get the app it just return an instance of Google_Service_Drive_App but there's nothing inside that to call the script with my post parameters.

UPDATE:

I am using the Google APIs Client Library for PHP

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

The user is authenticated through oAuth with \Google_Client(); with all the DRIVE scopes for permission.

My Google Script is located inside the user drive, and I'm trying to execute it remotely. I deployed the script as a web app. Below you can find the Script File url.

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

Basically I want the Google APIs Client Library for PHP to execute the Script File from the user drive.

I tried to use the Google_Http_Request class directly and execute it with the Google_Client, it almost worked as expected.

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

There are 1 answers

0
user1855153 On BEST ANSWER

I ended up using CURL request directly passing the "Authorization" header with the token_type and the access_token and it worked as expected. I didn't find any way to do this using the Google APIs Client Library for PHP

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