Shubham Angne
Shubham Angne

Reputation: 17

getting messaged id's from gmail is very slow

i have created class library using .net version 4.5 and language is c#. it is taking more than minutes to fetch just 6 emails from gmail API. below code i m using for getting mail details

public Message GetMailDetails(GmailService service, string EmailId, string MessageID)
{
            try
            {
                var a = service.Users.Messages.Get(EmailId, MessageID);
                a.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Metadata;
                var retMessage = a.Execute();


                //a.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Metadata;
                //retMessage = a.Execute();
                //a.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Minimal;
                //retMessage = a.Execute();
                //a.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
                //retMessage = a.Execute();
                return service.Users.Messages.Get(EmailId, MessageID).Execute();
            }
            catch (Exception e)
            {
                return null;
            }
 }

Upvotes: 1

Views: 446

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117271

What you can do is try to work with something called Partial response the easiest way to test this is to go through the try me page try me you will need a message id to test this

A full response from message.get would look like this

{
  "id": "1742abfd3a4f1c5",
  "threadId": "1742a8c81816e51",
  "labelIds": [
    "CHAT"
  ],
  "snippet": "I'm surprised nobody questioned me when I said that the tag was 2 weeks old, but clearly has questions from longer than 2 weeks ago. {:",
  "payload": {
    "partId": "",
    "mimeType": "text/html",
    "filename": "",
    "headers": [
      {
        "name": "From",
        "value": "Axxxx"
      }
    ],
    "body": {
      "size": 139,
      "data": "SSYjMzk7bSBzdXJwcmlzZWQgbm9ib2R5IHF1ZXN0aW9uZWQgbWUgd2hlbiBJIHNhaWQgdGhhdCB0aGUgdGFnIHdhcyAyIHdlZWtzIG9sZCwgYFybHkgaGFzIHF1ZXN0aW9ucyBmcm9tIGxvbmdlciB0aGFuIDIgd2Vla3MgYWdvLiB7Og=="
    }
  },
  "sizeEstimate": 100,
  "historyId": "6172496",
  "internalDate": "1598445048740"
}

By adding the fields paramater to your request fields=id,threadid the response then looks like this

{
  "id": "1742abfd3a4f16c5",
  "threadId": "1742a8c181816e51"
}

Basically you request only the fields of data you want to see.

example

var request =  service.Users.Messages.Get(EmailId, MessageID)
request.Fields = "id,threadid";
var response = request.Execute();

fields can be a bit tricky to get to work when you are trying to pick out stuff from arrays or list i really recommend testing it in the try me.

Upvotes: 1

Related Questions