Calling a google apps script execution api from PHP using a service account

imbibinebe

I'm trying to call a very simple google apps script from php using a service account so that only my server can access it, not users of the website.

Here is how I do. I create the script here https://script.google.com

function get() {
    return  ContentService.createTextOutput('get method');
}

and a new project is automatically associated when i save it. Then I open File > Project Properties to get the scriptId = MM8zQqofS1OIcnFiNSlm1CGEl5qMrMVBt

I access the developer console of the associated project threw Resources > Project Developers console by clicking on the project link at the top of the popup displayed.

Then I click 'Activate and manage API' and activate the 'Google Apps Script Execution API'. I click on 'Credentials' and see that the previous operation automatically created OAuth2 credentials. But what I need is service account credentials. Then I create one Add credentials > Service account and download generated p12 file. I get the clientId = 109160023321840004240 and clientMail = [email protected] for this service account.

I go back to my script and share it with the service account email with read&write access File > Share. First of all i get an email in my personal mailbox which notifies me that

Delivery to the following recipient failed permanently:

 [email protected]

Then I publish the script as an execution API Publish > Publish as an execution API with access to everybody.

Now lets go on the PHP server side. Using the 'Google APIs Client Library for PHP' available here https://github.com/google/google-api-php-client I try to call my script function from PHP:

$client = new Google_Client();
$client->setClientId('109160023321840004240');
$client->setApplicationName('myScript');

$cred = new Google_Auth_AssertionCredentials(
    '[email protected]',
    [/*no scope nedeed for this simple script*/],
    file_get_contents('path_to_myScript.p12')
);
$client->setAssertionCredentials($cred);

if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}

$service = new Google_Service_Script($client);
$scriptId = 'MM8zQqofS1OIcnFiNSlm1CGEl5qMrMVBt';

// Create an execution request object.
$request = new Google_Service_Script_ExecutionRequest();
$request->setFunction('get');
$response = $service->scripts->run($scriptId, $request);

And here is the response I get all the time

Error calling POST https://script.googleapis.com/v1/scripts/MM8zQqofS1OIcnFiNSlm1CGEl5qMrMVBt:run: (403) The caller does not have permission

If, when I deploy the script, I choose to give access to 'Me only', i get the following response.

Error calling POST https://script.googleapis.com/v1/scripts/MM8zQqofS1OIcnFiNSlm1CGEl5qMrMVBt:run: (404) Requested entity was not found.

I would be so happy if one of you have an idea to help me :)

Zig Mandel

apps script does not yet support service accounts with execution api. see https://code.google.com/p/google-apps-script-issues/issues/detail?id=5461

google said they are looking into it but apparently wont happen soon (based on google replies on google+ posts about this like https://plus.google.com/+MartinHawksey/posts/Zquix9XqzkK)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a google apps script execution api from PHP using a service account

From Dev

Calling Twitter API from Google Apps Script

From Dev

Google Apps Script Error while creating document using execution API PHP Client

From Dev

Google Apps Admin API: need to specify account user for service account?

From Dev

Google Apps Admin API: need to specify account user for service account?

From Dev

Google apps script execution API service authorization fails once per hour

From Dev

Calling Google Apps Script from a Chrome Extension

From Dev

How to create a Google Form using Google Apps Script Execution API + Java?

From Dev

How to create a Google Form using Google Apps Script Execution API + Java?

From Dev

Using Dart googleapis_auth (0.2.2) to authorize Admin SDK Directory API in Google Apps domains with service account

From Dev

Error 404 when calling Google Cloud Endpoint API from Google Apps Script

From Dev

Enable mail forwarding using a Google Apps Service Account

From Dev

Using service account to copy the apps

From Dev

accessing Twitter API from Google Apps Script

From Dev

Using Google Apps Marketplace to register service account in Google Apps for Work Domain

From Dev

Calling a Google App Script from PHP?

From Dev

How to request unsampled report from Google Analytics Management API using Google Apps Script?

From Dev

What is the difference between Google Rest API and Google Apps Script Execution API

From Dev

What is the difference between Google Rest API and Google Apps Script Execution API

From Dev

php | Google Webmaster API Service Account has no permission

From Dev

Unable to query Google Search Console API using a Service Account

From Dev

Ownership of Google Drive files and Service Account using API

From Dev

Get users by Department from Admin Directory API using Google Apps Script

From Dev

How to download file from google drive api with service account?

From Dev

Google Drive API - Transfer ownership from Service Account

From Dev

How to send List of objects to google execution api and handle it in google apps script

From Dev

Google Apps Script - exceeded maximum execution time

From Dev

Infinite execution of the code in google apps script

From Dev

Google APPs managed "unlimited" account storage quota for service account

Related Related

  1. 1

    Calling a google apps script execution api from PHP using a service account

  2. 2

    Calling Twitter API from Google Apps Script

  3. 3

    Google Apps Script Error while creating document using execution API PHP Client

  4. 4

    Google Apps Admin API: need to specify account user for service account?

  5. 5

    Google Apps Admin API: need to specify account user for service account?

  6. 6

    Google apps script execution API service authorization fails once per hour

  7. 7

    Calling Google Apps Script from a Chrome Extension

  8. 8

    How to create a Google Form using Google Apps Script Execution API + Java?

  9. 9

    How to create a Google Form using Google Apps Script Execution API + Java?

  10. 10

    Using Dart googleapis_auth (0.2.2) to authorize Admin SDK Directory API in Google Apps domains with service account

  11. 11

    Error 404 when calling Google Cloud Endpoint API from Google Apps Script

  12. 12

    Enable mail forwarding using a Google Apps Service Account

  13. 13

    Using service account to copy the apps

  14. 14

    accessing Twitter API from Google Apps Script

  15. 15

    Using Google Apps Marketplace to register service account in Google Apps for Work Domain

  16. 16

    Calling a Google App Script from PHP?

  17. 17

    How to request unsampled report from Google Analytics Management API using Google Apps Script?

  18. 18

    What is the difference between Google Rest API and Google Apps Script Execution API

  19. 19

    What is the difference between Google Rest API and Google Apps Script Execution API

  20. 20

    php | Google Webmaster API Service Account has no permission

  21. 21

    Unable to query Google Search Console API using a Service Account

  22. 22

    Ownership of Google Drive files and Service Account using API

  23. 23

    Get users by Department from Admin Directory API using Google Apps Script

  24. 24

    How to download file from google drive api with service account?

  25. 25

    Google Drive API - Transfer ownership from Service Account

  26. 26

    How to send List of objects to google execution api and handle it in google apps script

  27. 27

    Google Apps Script - exceeded maximum execution time

  28. 28

    Infinite execution of the code in google apps script

  29. 29

    Google APPs managed "unlimited" account storage quota for service account

HotTag

Archive