0

I'm getting 404 error when I post request to google execution api from chrome extension.

I'm sure my client id is correct and scopes are correct. Also, my script id and function name to call are correct as well.

I also published the script as api executable to everyone.

Here is my sample chrome extension files.

Please give me a help!

I've been stuck with this problem for a long time.

manifest.json

{
  "name": "Execution Api Test",
  "version": "0.1",
  "manifest_version": 2,

  "description": "Execution Api Test",

  "permissions": [
    "identity",
    "tabs",
    "http://*/*",
    "https://*/*"
  ],

  "background": {
    "scripts": ["background.js"]
  },

  "oauth2": {

    "client_id": "816912884742-icjd8pjj58m4rvrh211f1rrg97bkepho.apps.googleusercontent.com",

    "scopes": [
      "https://www.googleapis.com/auth/spreadsheets"
    ]

  },

  "page_action": {
    "default_icon": "icon.png",
    "default_title": "test"
  }


}

background.js

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
        chrome.pageAction.show(tabId);

});


chrome.pageAction.onClicked.addListener(function () {

    chrome.identity.getAuthToken(

        {'interactive': true},

        function(token) {

            //I get access token successfully.
            console.log(token);

            var scriptID = "MR4ao03vpkqX-hTekNkflNDxdZGPvncRS";

            var apiURL = "https://script.googleapis.com/v1/scripts/" + scriptID + ":run";

            var requestBody = {
                "function": "myFunction",
                "devMode": true
            };

            var xhr = new XMLHttpRequest();
            xhr.open('POST', apiURL, true);

            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.setRequestHeader('Authorization', 'Bearer ' + token);

            xhr.send(JSON.stringify(requestBody));


        });

});

# All Information that I need!!!

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • If it's an **Error 404 - Requested entity not found**, checking suggested solutions in [Issue 5417](https://code.google.com/p/google-apps-script-issues/issues/detail?id=5417) from google-apps-script-issues might work wherein one solution given is to make sure that your script is associated with the same Google Developer console project that you used for authentication. Did it work fine? Please share if it worked on your end. :) – Teyam May 02 '16 at 10:57
  • I posted additional information!! Could you take a look if you have a time please? Am I missing something or doing something wrong?? –  May 03 '16 at 04:32
  • Did you use dev console project that you created by yourself and not the default one that was associated automatically? How about project ID - **cwcfhultxzewaetqjli** which was associated to execution API? I notice different project IDs. – Teyam May 04 '16 at 02:36
  • I'm sorry! I inserted the wrong screen-capture image. I replaced the wrong image with the right one. It shows that "projectID" is cwcfhultxzewaetqjli in the dev console project window. To answer your question, I did use the dev console project that was associated automatically. –  May 04 '16 at 04:27
  • actually, to post this question, I created new app script and went through all steps I need to call execution api. All information I posted is from the new sample project I created for this post. Now, I get 403 error not 404 error. I'm so stuck with this thing. –  May 04 '16 at 04:29
  • You should try to use Developer console project that you created. Do not depend on the default one that was associated automatically. Please refer to [this](https://developers.google.com/identity/sign-in/web/devconsole-project) – Teyam May 04 '16 at 06:17
  • Did you find the problem? I have the same and strange Google returns 404 when I try to use "devMode": true. – Martin Dimitrov Jun 28 '16 at 13:29
  • no, ive given up on this problem. –  Jun 28 '16 at 13:34

1 Answers1

0

There is an issue with Google Execution API. For now you can't use service accounts for Exection API. There is ticket for tracking: https://code.google.com/p/google-apps-script-issues/issues/detail?id=5461 And it contains possible workaround. Also you can use this in your GScript to authorize properly: https://github.com/googlesamples/apps-script-oauth2

Igor Matsko
  • 59
  • 1
  • 1
  • 12