How to retrieve my Gmail messages using Gmail API?

后端 未结 5 1086
忘掉有多难
忘掉有多难 2020-12-14 04:35

What I want to achieve:


I\'m using the Gmail API and basically I would like to connect to my GMail account to read my emails, of INBOX categ

5条回答
  •  我在风中等你
    2020-12-14 04:54

    First: up-vote @codexer 's answer.

    Second, use the following function in his code to decode the base64URL encoded body. Google not only base64 encoded the body, it is also URL encoded :-/

    /// 
        /// Turn a URL encoded base64 encoded string into readable UTF-8 string.
        /// 
        /// base64 URL ENCODED string.
        /// UTF-8 formatted string
        private string DecodeURLEncodedBase64EncodedString(string sInput)
        {
            string sBase46codedBody = sInput.Replace("-", "+").Replace("_", "/").Replace("=", String.Empty);  //get rid of URL encoding, and pull any current padding off.
            string sPaddedBase46codedBody = sBase46codedBody.PadRight(sBase46codedBody.Length + (4 - sBase46codedBody.Length % 4) % 4, '=');  //re-pad the string so it is correct length.
            byte[] data = Convert.FromBase64String(sPaddedBase46codedBody);
            return Encoding.UTF8.GetString(data);
        }
    

提交回复
热议问题