Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/discovery/v1/apis/script/v1/rest returned "Request contains an invalid argument."> #83

Closed
majestique opened this issue Feb 22, 2019 · 3 comments

Comments

@majestique
Copy link

majestique commented Feb 22, 2019

Update: It looks like this is where the error is occurring:
image

Here's what it says about the build function:
image

Original Post:
I'm not sure which part of the request is broken, I tried using the original request from the sample code but still has the same error. I also tried just using 1 scope, without parameter, different function name, quote the "123" in the request object. Still no luck. Any help is appreciated, thanks!

Using this script based on https://developers.google.com/apps-script/api/how-tos/execute & https://github.com/gsuitedevs/python-samples/blob/364cd15a3e8949048fd2731ec941dd57169ee2ba/apps_script/execute/execute.py#L16-L79

My script:

    SCRIPT_ID = '1WChnVrk5gycQEtumI7mPi5PexXafuhBAWN7-VnBK2aPkFpzMHtUp0cnx'


    # Setup the Apps Script API
    SCOPES = 'https://www.googleapis.com/auth/script.projects'
    store = oauth_file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('script', 'v1', http=creds.authorize(Http()))

    # Create an execution request object.
    request = {"function": "myFunction", "parameters": [{"salesID" : 123}]}

I'm getting this error:
image

Google app script function:

function myFunction(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var timestamp = new Date();

sheet.getRange("A2").setValue(e.salesID);
sheet.getRange("B2").setValue(timestamp);
}

Public Google Sheet:
https://docs.google.com/spreadsheets/d/1Z4PAY3CCaRorn5LRdFQKn4-EcAHxwxHJsABzEgsSQk0/edit#gid=0

  • Python version 3.7.2
  • OS Centos 7
@majestique
Copy link
Author

majestique commented Feb 23, 2019

So the error suggests something's wrong w/ the token.json (according to this: https://stackoverflow.com/questions/43260440/error-in-request-for-google-cloud-speech-api-request) that was generated, so it looks like google is generating that file incorrectly. Here's what mine looks like:

{
  "access_token": "yXXXXXX",
  "client_id": "DDDDDD.apps.googleusercontent.com",
  "client_secret": "GGGG",
  "refresh_token": "1DFDSFDSF",
  "token_expiry": "2019-02-22T21:17:02Z",
  "token_uri": "https://oauth2.googleapis.com/token",
  "user_agent": null,
  "revoke_uri": "https://oauth2.googleapis.com/revoke",
  "id_token": {
    "iss": "https://accounts.google.com",
    "azp": "5555.apps.googleusercontent.com",
    "aud": "5555.apps.googleusercontent.com",
    "sub": "1ggggg",
    "hd": "mydomain.com",
    "email": "info@mydomain.com",
    "email_verified": true,
    "at_hash": "asdfasdf",
    "iat": 1550866621,
    "exp": 1550870221
  },
  "id_token_jwt": "asdfasdfasdffsda",
  "token_response": {
    "access_token": "yaasdfasdf",
    "expires_in": 3600,
    "refresh_token": "1/asdfasdf",
    "scope": "https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/script.cpanel https://www.googleapis.com/auth/script.send_mail https://www.googleapis.com/auth/script.storage https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets.currentonly https://www.googleapis.com/auth/script.external_request https://www.googleapis.com/auth/spreadsheets https://apps-apis.google.com/a/feeds/ https://www.googleapis.com/auth/documents.currentonly https://www.googleapis.com/auth/script.scriptapp https://www.googleapis.com/auth/script.webapp.deploy https://apps-apis.google.com/a/feeds/alias/ https://www.googleapis.com/auth/sqlservice https://www.googleapis.com/auth/admin.directory.group https://apps-apis.google.com/a/feeds/groups/ https://www.googleapis.com/auth/dynamiccreatives https://www.googleapis.com/auth/contacts https://www.googleapis.com/auth/forms openid https://mail.google.com/ https://www.googleapis.com/auth/calendar http://sites.google.com/feeds https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/forms.currentonly https://www.googleapis.com/auth/groups",
    "token_type": "Bearer",
    "id_token": "afsdasdf"
  },
  "scopes": [ "https://www.googleapis.com/auth/forms.currentonly", "https://www.googleapis.com/auth/script.storage", "https://sites.google.com/feeds", "https://www.googleapis.com/auth/documents.currentonly", "https://www.googleapis.com/auth/groups", "https://www.googleapis.com/auth/script.webapp.deploy", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/sqlservice", "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/admin.directory.group", "https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/script.send_mail", "https://www.google.com/calendar/feeds", "https://www.googleapis.com/auth/dynamiccreatives", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/spreadsheets.currentonly", "https://apps-apis.google.com/a/feeds", "https://www.googleapis.com/auth/spreadsheets", "https://apps-apis.google.com/a/feeds/groups/", "https://www.googleapis.com/auth/script.cpanel", "https://apps-apis.google.com/a/feeds/alias/", "https://mail.google.com/", "https://www.googleapis.com/auth/admin.directory.user", "https://www.googleapis.com/auth/script.scriptapp", "https://www.googleapis.com/auth/forms", "https://www.google.com/m8/feeds" ],
  "token_info_uri": "https://oauth2.googleapis.com/tokeninfo",
  "invalid": false,
  "_class": "OAuth2Credentials",
  "_module": "oauth2client.client"
}

@p-doyle
Copy link

p-doyle commented Feb 23, 2019

I was having the exact same issue, see here googleapis/google-api-python-client#628.

You should be able to get it to work by changing:

service = build('script', 'v1', http=creds.authorize(Http()))

to

service = build('script', 'v1', credentials=creds)

@majestique
Copy link
Author

Thanks! Looks like it works but the problem might be this isn't a long term solution since oauth2client is deprecating https://google-auth.readthedocs.io/en/latest/oauth2client-deprecation.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants