Can I get the URL link for a Gmail project using the Gmail API?

The new Gmail API allows us to create and view drafts, but is there a way to get a URL link to view a draft?

I can manually create the link using the ThreadId project, with something like this:

https://mail.google.com/mail/u/0/#drafts?compose= {ThreadId}

But it's a bit fragile if Google decides to change the way that these URLs are structured. I also don't know if the URL will be to other people. 0 will also change depending on how many accounts you have logged into the browser. Is there a better way to get this link than manually creating it like me?

Also, is there a way to pass authentication information along with the URL so that the user logs in when they go to the web page? I suppose there is no way to do this, but I wanted to check. If the user is not logged in, the draft link brings up the login page, and the draft is not displayed after logging in.

+7
source share
2 answers

No, manually creating a URL is currently your best option. You can opt out of u/0/ if you want, and Gmail automatically uses the first authenticated account.

No, you cannot automatically subscribe a user to Gmail.

+2
source

In order to provide the URL to the draft API created, this works:

 ... final Gmail.Users.Drafts.Create request = gmailService.users().drafts().create("me", content); final Draft response = request.execute(); final String url = "https://mail.google.com/mail/ca/u/0/#drafts/" + response.getMessage().getThreadId() ... 

When a user clicks on it, gmail redirects (and redirects) to another URL, but opens the correct draft. However, I did not find a mention of this in the documentation, so this may be an unsupported function that stops working once.

Credits: @Chris Wood from this SO question stackoverflow.com/q/50124112/455449 (see his comment below the question)

0
source

Source: https://habr.com/ru/post/971445/


All Articles