python - Using googleapiclient to send an email draft by Id -


i'm using google's api client interact gmail api. assuming have draft's immutable id, i'd send associated draft.

i tried:

service.users().drafts().send(     userid='me', id=draft_id).execute(http=http) 

here draft_id id of draft i'd send, http instance of http works other requests (so authenticated).

trying above, typeerror:

traceback (most recent call last):   file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch     return method(*args, **kwargs)   file "/users/mgilson/git/spider-web/app/pattern/handlers/ajax/email.py", line 77, in post     'success': int(client.send_draft(draft_id))   file "/users/mgilson/git/spider-web/app/pattern/services/email/gmail.py", line 601, in send_draft     userid='me', id=draft_id) \   file "/users/mgilson/git/spider-web/app/third_party/googleapiclient/discovery.py", line 669, in method     raise typeerror('got unexpected keyword argument "%s"' % name) typeerror: got unexpected keyword argument "id" 

the documentation has java example, no python example.

other variations i've tried:

service.users().drafts().send(     userid='me', draftid=draft_id).execute(http=http)  service.users().drafts().send(     userid='me', draft_id=draft_id).execute(http=http)  service.users().drafts().send(     userid='me', body={'draft': {'id': draft_id}}).execute(http=http) 

the last 1 gives different error:

traceback (most recent call last):   file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch     return method(*args, **kwargs)   file "/users/mgilson/git/spider-web/app/pattern/handlers/ajax/email.py", line 77, in post     'success': int(client.send_draft(draft_id))   file "/users/mgilson/git/spider-web/app/pattern/services/email/gmail.py", line 603, in send_draft     .execute(http=self._http)   file "/users/mgilson/git/spider-web/app/third_party/oauth2client/util.py", line 140, in positional_wrapper     return wrapped(*args, **kwargs)   file "/users/mgilson/git/spider-web/app/third_party/googleapiclient/http.py", line 729, in execute     raise httperror(resp, content, uri=self.uri) httperror: <httperror 400 when requesting https://www.googleapis.com/gmail/v1/users/me/drafts/send?alt=json returned "invalid draft"> 

which makes me feel might moving in correct direction ... (note, i've been able use ids send messages api explorer linked above, i'm confident i'm working valid ids)

what's right way send data?


i'm not sure how relevant is, discovery api's representation of gmail api can found @ https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest

specifically, think method i'm working defined following json:

  "send": {    "id": "gmail.users.drafts.send",    "path": "{userid}/drafts/send",    "httpmethod": "post",    "description": "sends specified, existing draft recipients in to, cc, , bcc headers.",    "parameters": {     "userid": {      "type": "string",      "description": "the user's email address. special value me can used indicate authenticated user.",      "default": "me",      "required": true,      "location": "path"     }    },    "parameterorder": [     "userid"    ],    "request": {     "$ref": "draft"    },    "response": {     "$ref": "message"    },    "scopes": [     "https://mail.google.com/",     "https://www.googleapis.com/auth/gmail.compose",     "https://www.googleapis.com/auth/gmail.modify"    ],    "supportsmediaupload": true,    "mediaupload": {     "accept": [      "message/rfc822"     ],     "maxsize": "35mb",     "protocols": {      "simple": {       "multipart": true,       "path": "/upload/gmail/v1/users/{userid}/drafts/send"      },      "resumable": {       "multipart": true,       "path": "/resumable/upload/gmail/v1/users/{userid}/drafts/send"      }     }    }   }, 

looking @ gmail api python docs, looks second parameter body of request. according gmail api reference, need id field in body draftid of draft want send:

service.users().drafts().send(     userid='me', body={ 'id': draft_id }).execute(http=http) 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -