Gmail API batch get support?












3














I am doing WEB HTTP calls using Gmail API. Is there a way to batch get message content?



It seems that messages.list only returns messageIds, and messages.get only support single message query.



LIST API: https://www.googleapis.com/gmail/v1/users/userId/messages
GET API: https://www.googleapis.com/gmail/v1/users/userId/messages/id



Help me guys~ Thank you!










share|improve this question
























  • Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
    – SGC
    Feb 20 '15 at 20:12










  • Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
    – Jun Zhou
    Feb 24 '15 at 20:08
















3














I am doing WEB HTTP calls using Gmail API. Is there a way to batch get message content?



It seems that messages.list only returns messageIds, and messages.get only support single message query.



LIST API: https://www.googleapis.com/gmail/v1/users/userId/messages
GET API: https://www.googleapis.com/gmail/v1/users/userId/messages/id



Help me guys~ Thank you!










share|improve this question
























  • Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
    – SGC
    Feb 20 '15 at 20:12










  • Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
    – Jun Zhou
    Feb 24 '15 at 20:08














3












3








3







I am doing WEB HTTP calls using Gmail API. Is there a way to batch get message content?



It seems that messages.list only returns messageIds, and messages.get only support single message query.



LIST API: https://www.googleapis.com/gmail/v1/users/userId/messages
GET API: https://www.googleapis.com/gmail/v1/users/userId/messages/id



Help me guys~ Thank you!










share|improve this question















I am doing WEB HTTP calls using Gmail API. Is there a way to batch get message content?



It seems that messages.list only returns messageIds, and messages.get only support single message query.



LIST API: https://www.googleapis.com/gmail/v1/users/userId/messages
GET API: https://www.googleapis.com/gmail/v1/users/userId/messages/id



Help me guys~ Thank you!







rest google-api gmail batch-processing gmail-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 20 '15 at 20:34









SomethingDark

7,82642736




7,82642736










asked Feb 20 '15 at 19:41









Jun Zhou

262




262












  • Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
    – SGC
    Feb 20 '15 at 20:12










  • Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
    – Jun Zhou
    Feb 24 '15 at 20:08


















  • Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
    – SGC
    Feb 20 '15 at 20:12










  • Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
    – Jun Zhou
    Feb 24 '15 at 20:08
















Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
– SGC
Feb 20 '15 at 20:12




Instead of sending each call separately, you can group them together into a single HTTP request. You can even group requests for multiple users or multiple Google APIs. You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. check this link on batching developers.google.com/gmail/api/guides/batch?hl=de-LU which has sample example GET request and PUT request
– SGC
Feb 20 '15 at 20:12












Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
– Jun Zhou
Feb 24 '15 at 20:08




Thank you SGC, this is exactly what I am looking for. I really wish Gmail can support it better so we don't need to handroll these multipart POST calls.
– Jun Zhou
Feb 24 '15 at 20:08












2 Answers
2






active

oldest

votes


















2














You can definitely do batched messages.get(), quite a few questions covering it already:
https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch






share|improve this answer































    0














    The gmail API returns only messageIds first to prevent heavy load.
    With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.



    After getting the partialMessages(message ids) use this :



    List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);

    private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
    try {

    final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
    public void onSuccess(Message message, HttpHeaders responseHeaders) {
    fullyQualifiedMessageList.add(message);
    }

    public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
    // do what you want if error occurs
    }
    };

    BatchRequest batch = mService.batch();
    for (Message message : partialMessages) {
    mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
    }
    batch.execute();


    } catch (IOException e) {
    e.printStackTrace();
    }

    Log.d(TAG, "Message" + fullyQualifiedMessageList.size());


    return fullyQualifiedMessageList;
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28636938%2fgmail-api-batch-get-support%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You can definitely do batched messages.get(), quite a few questions covering it already:
      https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch






      share|improve this answer




























        2














        You can definitely do batched messages.get(), quite a few questions covering it already:
        https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch






        share|improve this answer


























          2












          2








          2






          You can definitely do batched messages.get(), quite a few questions covering it already:
          https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch






          share|improve this answer














          You can definitely do batched messages.get(), quite a few questions covering it already:
          https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '17 at 12:31









          Community

          11




          11










          answered Feb 20 '15 at 20:11









          Eric D

          5,4641822




          5,4641822

























              0














              The gmail API returns only messageIds first to prevent heavy load.
              With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.



              After getting the partialMessages(message ids) use this :



              List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);

              private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
              try {

              final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
              public void onSuccess(Message message, HttpHeaders responseHeaders) {
              fullyQualifiedMessageList.add(message);
              }

              public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
              // do what you want if error occurs
              }
              };

              BatchRequest batch = mService.batch();
              for (Message message : partialMessages) {
              mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
              }
              batch.execute();


              } catch (IOException e) {
              e.printStackTrace();
              }

              Log.d(TAG, "Message" + fullyQualifiedMessageList.size());


              return fullyQualifiedMessageList;
              }





              share|improve this answer




























                0














                The gmail API returns only messageIds first to prevent heavy load.
                With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.



                After getting the partialMessages(message ids) use this :



                List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);

                private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
                try {

                final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
                public void onSuccess(Message message, HttpHeaders responseHeaders) {
                fullyQualifiedMessageList.add(message);
                }

                public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                // do what you want if error occurs
                }
                };

                BatchRequest batch = mService.batch();
                for (Message message : partialMessages) {
                mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
                }
                batch.execute();


                } catch (IOException e) {
                e.printStackTrace();
                }

                Log.d(TAG, "Message" + fullyQualifiedMessageList.size());


                return fullyQualifiedMessageList;
                }





                share|improve this answer


























                  0












                  0








                  0






                  The gmail API returns only messageIds first to prevent heavy load.
                  With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.



                  After getting the partialMessages(message ids) use this :



                  List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);

                  private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
                  try {

                  final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
                  public void onSuccess(Message message, HttpHeaders responseHeaders) {
                  fullyQualifiedMessageList.add(message);
                  }

                  public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                  // do what you want if error occurs
                  }
                  };

                  BatchRequest batch = mService.batch();
                  for (Message message : partialMessages) {
                  mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
                  }
                  batch.execute();


                  } catch (IOException e) {
                  e.printStackTrace();
                  }

                  Log.d(TAG, "Message" + fullyQualifiedMessageList.size());


                  return fullyQualifiedMessageList;
                  }





                  share|improve this answer














                  The gmail API returns only messageIds first to prevent heavy load.
                  With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.



                  After getting the partialMessages(message ids) use this :



                  List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);

                  private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
                  try {

                  final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
                  public void onSuccess(Message message, HttpHeaders responseHeaders) {
                  fullyQualifiedMessageList.add(message);
                  }

                  public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                  // do what you want if error occurs
                  }
                  };

                  BatchRequest batch = mService.batch();
                  for (Message message : partialMessages) {
                  mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
                  }
                  batch.execute();


                  } catch (IOException e) {
                  e.printStackTrace();
                  }

                  Log.d(TAG, "Message" + fullyQualifiedMessageList.size());


                  return fullyQualifiedMessageList;
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 12 at 20:12









                  mkobit

                  20.3k68499




                  20.3k68499










                  answered Jul 6 at 5:50









                  Ajay Gowtam

                  363




                  363






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28636938%2fgmail-api-batch-get-support%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python