Generate gmail-attachment url to view

断了今生、忘了曾经 提交于 2021-02-08 07:31:57

问题


I'm working on project which can access all the pictures in g-mail.I've tried the G-mail API using node which can fetch all required attachments.But that requires to download the whole image.I can access the attachment id and message id using the API.Is there any way to generate the url of attachment (to view) so that i can provide a link to the required image from my project.


回答1:


I actually found this related issue, Issue #134, and you may want to try the suggested solution.

You may fetch email attachments using this:

https://mail.google.com/mail/u/0/?ui=2&ik={ik_value}&view=att&th={message_id}&attid=0.{atachment_index}&disp=safe&zw

wherein, attachmment_index is just the index of the attachment. If there are 3 attachments and you want to get the 3rd file, the index value will be 3. This URL is a 302 header that acts like a link shortener for the download file. Opening this link will lead you to the attachment data

var ik = gmail.tracker.ik;
var id = gmail.get.email_id();
var aid = "1"; // gets the first attachment

var url = "https://mail.google.com/mail/u/0/?ui=2&ik=" + ik + "&view=att&th=" + id + "&attid=0." + aid + "&disp=safe&zw";

console.log(url);


来源:https://stackoverflow.com/questions/42166981/generate-gmail-attachment-url-to-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!