python - Cannot get to Google Execution API and receiving 500 Internal error -
i have created script in apps script , deployed api executable. started 500 error when connecting it. decided create script tutorial localize issue error. surprise received same results. issue service account, because associated script project have service account , try authorize it.
i read there issues connecting execution api service account, can still true today.
***update: have accessed execution api tutorial script when using oauth2 user client id. there still issue connecting execution api using service account?
here apps script deployed api executable project have service account:
/** * function in script called apps script execution api. */ /** * return set of folder names contained in user's root folder * object (with folder ids keys). * @return {object} set of folder names keyed folder id. */ function getfoldersunderroot() { var root = driveapp.getrootfolder(); var folders = root.getfolders(); var folderset = {}; while (folders.hasnext()) { var folder = folders.next(); folderset[folder.getid()] = folder.getname(); } return folderset; } here partly modified code took tutorial. changed work service account:
from googlepackage.api_client import * googlepackage.constants import * googleapiclient.errors import httperror httplib2 import http def __get_credentials(scopes: list) -> serviceaccountcredentials: credential_dir = os.path.join("..\\", service_account_folder) print(credential_dir) if not os.path.exists(credential_dir): raise exception("cannot find directory credentials") try: credentials = serviceaccountcredentials.from_json_keyfile_name( os.path.join(credential_dir, 'file.json'), scopes) except (valueerror, keyerror) error: raise exception(error) return credentials def main(): """shows basic usage of apps script execution api. creates apps script execution api service object , uses call apps script function print out list of folders in user's root directory. """ script_id = 'api id' http_auth = __get_credentials([read_and_write_scope, drive_api_scope]).authorize(http()) # authorize , create service object. service = discovery.build('script', 'v1', http=http_auth) # create execution request object. request = {"function": "getfoldersunderroot"} try: # make api request. response = service.scripts().run(body=request, scriptid=script_id).execute() if 'error' in response: # api executed, script returned error. # extract first (and only) set of error details. values of # object script's 'errormessage' , 'errortype', , # list of stack trace elements. error = response['error']['details'][0] print("script error message: {0}".format(error['errormessage'])) if 'scriptstacktraceelements' in error: # there may not stacktrace if script didn't start # executing. print("script error stacktrace:") trace in error['scriptstacktraceelements']: print("\t{0}: {1}".format(trace['function'], trace['linenumber'])) else: # structure of result depend upon apps script # function returns. here, function returns apps script object # string keys , values, , result treated # python dictionary (folderset). folderset = response['response'].get('result', {}) if not folderset: print('no folders returned!') else: print('folders under root folder:') (folderid, folder) in folderset.items(): print("\t{0} ({1})".format(folder, folderid)) except httperror e: # api encountered problem before script started executing. print(e.content) if __name__ == '__main__': main() here httperror content response:
b'{\n "error": {\n "code": 500,\n "message": "internal error encountered.",\n "errors": [\n {\n "message": "internal error encountered.",\n "domain": "global",\n "reason": "backenderror"\n }\n ],\n "status": "internal"\n }\n}\n'
update: have accessed execution api tutorial script when using oauth2 user client id.
i still not able through execution api using service account , credentials. connect execution api oauth2 client id.
so now, suggest using 2 accounts access google sheets api service account , execution api oauth2 client id
Comments
Post a Comment