2
votes

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
Are you trying to do something like this with your Google Apps Script as the 2nd server? You can't get a list of the functions inside a script through that API - see resource representation. You should instead implement your Google Apps Script web service to use ContentService to provide the responses to your PHP posts.Mogsdad
I use the "doPost" function, I can execute the script with CURL without problem, but I need to run it "as the current google client", not as anonymous. Do I need to add something into my curl post request to let google know who exactly is running the script.user1855153
That sounds different than your question... maybe you need to edit the question to make it clearer what your SPECIFIC problem is. Have you seen User authentication in PHP?Mogsdad

1 Answers

1
votes

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