我正在嘗試回圈瀏覽一組電子郵件,并獲得它們的電子郵件附件ID。 但是,我似乎無法找到ID。
我已經走到了這一步:
我已經走到了這一步。
class AccessEmailController < ApplicationController
def access_email
client = Signet::OAuth2::Client.new(access_token: session[:access_token] )
service = Google::Apis::GmailV1::GmailService.new
service.authorization = client
user_id = 'me'/span>
email_list = service.list_user_messages('me', q: "subject:(CCC資料)")
message = 'No Emails Found' if email_list.mages.empty?
email_list.messages.each do|message|
message_id = message.id
@subject = service.get_user_message(user_id, message_id).payload.partals
end[/span]>
結束。
結束
而且,如果我在一個視圖中顯示@subject,我得到:
[#<Google::Apis::GmailV1::MessagePart:0x00007f8630c397a0 @headers=[#<Google::Apis::GmailV1::MessagePartHeader。 0x00007f8630c344a8 @name="Content-Type", @value="multipart/alternative; boundary="00000000000020396d05b7ceda38""> ], @mime_type="multipart/alternative", @body=#<谷歌。 :Apis::GmailV1::MessagePartBody: 0x00007f8630c39250 @size=0> , @filename="", @part_id="0", @parts=[#<谷歌。 :Apis::GmailV1::MessagePart:0x00007f8630c30588 @headers=[#<Google::Apis:: GmailV1::MessagePartHeader: 0x00007f8630c2d2e8 @name="Content-Type", @value="text/plain; charset="UTF-8"">], @mime_type="text/plain"/span>, @body=#<Google: :Apis::GmailV1::MessagePartBody:0x00007f8630c2ed50 @size=91, @data="--
金-弗洛伊德(戴維斯
網路開發人員,EvenVision
707.845.3073
[email protected]
">, @filename=", @part_id="0。 0">, #<Google::Apis::GmailV1::MessagePart:0x00007f8630c2be98 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c2a840 @name="Content-Type", @value="text/html; charset="UTF-8"">, #<Google::Apis::GmailV1:: MessagePartHeader:0x00007f8630c29ff8 @name="Content-Transfer-Encoding", @value="quoted-printable">], @mime_type="text/html"/span>, @body=#<Google: :Apis::GmailV1::MessagePartBody: 0x00007f8630c2b858 @size=344, @data="<div dir="ltr"><br clear="all"><div><br>--<br>< div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Kim Floyd (Davis)<div><br><div>Web Developer, EvenVision</div> <div>707. 845.3073</div><div><a href="mailto:[email protected]" target="_blank">[email protected]</a></div></div></div>。
">, @filename="/span>, @part_id="0。 1">]>, #<Google::Apis::GmailV1::MessagePart:0x00007f8630c28f68 @headers=[#<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c27b90 @name="內容-型別", @value="image/png; name="image. png"">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c26fd8 @name="Content-Disposition", @value="attachment; fileename="image. png"">, #<Google::Apis::GmailV1::MessagePartHeader:0x00007f8630c266f0 @name="Content-Transfer-Encoding", @value="base64">, #<Google: :Apis::GmailV1::MessagePartHeader:0x00007f8630c25d40 @name="X-Attachment-Id", @value="f_kjdr80n00">, #<谷歌。 :Apis::GmailV1::MessagePartHeader:0x00007f8630c25250 @name="Content-ID", @value="<f_kjdr80n00>">], @mime_type="/span>image/png", @body=#<谷歌。 :Apis::GmailV1::MessagePartBody: 0x00007f8630c28a90 @size=459005, @attachment_id="/span>ANGjdJ9LKnYW-GChtR3_oaBWnwi0DjHG4I8ZeDuMskuJ6htxLGmwNaB-v3x0k_cP94ybJFg0HLPO0AkSLWb- zXvF25qaGyhA20R89kwPSC9j3ttVEsBhByEAxrPkJQVwKuf3H8EblPhNNfPA7iYEJ7zT56do8-_UbMbDuXo-fVU445mtPHSYHWOEX_4z8aUyNTU3MCzNY8EHz90mJRpJnseelK3whaZdcJ2E98XmxQ"> , @filename="image. png", @part_id="1">] 。
其中,確實包含我正在尋找的附件。 但是,我怎樣才能找到那個附件,并得到它的ID呢?
uj5u.com熱心網友回復:
email_list.mages.each do |msg|
message = gmail.get_user_message(user_id, msg.id)
parts = message.payload.parts || [] 。
parts.each do |part|
p part.body.attachment_id
end
end end
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/313838.html
標籤:
下一篇:試圖為一個特殊的游戲獲取評論
