Resumable Dowload with Gmail API

96 views
Skip to first unread message

di...@nubbius.com

unread,
Nov 2, 2015, 1:16:16 PM11/2/15
to google-api-java-client, Desarrollo nubbius
Hi, 

I'm trying to apply resumable donload with gmail API, getting an Message, following these principles: https://google-developers.appspot.com/api-client-library/java/google-api-java-client/media-download [1]

However, I don't find a method of Getting message thorugh that use MediaHttpDownloader,in a similar way that insert method message, has one with MediaHttpUploader

I'm trying to get a message without service-specific generated libraries, following this example for Drive [1].

Instead of using:

DriveFiles.Get request = drive.files().get(fileId);
request
.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
request
.executeMediaAndDownloadTo(out);

In drive you must use:

MediaHttpDownloader downloader = new MediaHttpDownloader(transport, httpRequestInitializer);
downloader
.setProgressListener(new CustomProgressListener());
downloader
.download(requestUrl, out);



I get YOUR_API_KEY from Google Credential method, getAccessToken().

I try this code, but I think I have problems with OutputStream

                        ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpTransport transportHttp = new UrlFetchTransport();

String request = "https://www.googleapis.com/gmail/v1/users/me/messages/"+idMensaje+"?format=raw&fields=raw&key="+key;
GenericUrl genericURL = new GenericUrl(request);

MediaHttpDownloader downloader = new MediaHttpDownloader(transportHttp, serviceUserGmail.getRequestFactory().getInitializer());
downloader.setDirectDownloadEnabled(false);
downloader.setChunkSize(1024 * 1024);
downloader.download(genericURL, out);

I get this error:

com.google.api.client.http.HttpResponseException: 400
Unsupported Output Format
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:245)
at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:199)
at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:156)

How I must define outputStream out? (if this is the error?

Thanks.


___
Nota:
 Según la normativa vigente en materia de Protección de Datos de Carácter Personal, le informamos que sus datos han sido incorporados a un fichero denominado "Clientes y/o Proveedores" creado por resolución de la Agencia Española de Protección de Datos y del que es responsable "The Cloud Gate S.L.", con CIF: B-18961433. La finalidad del tratamiento de sus datos es mantener la relación contractual existente o mantenerle informado de novedades y noticias que puedan resultar de su interés. Le informamos que usted puede ejercitar sus derechos de acceso, rectificación, cancelación y oposición, mediante escrito dirigido a: "The Cloud Gate S.L.", Avda. Constitución 22, 1º 8 - 18012 Granada, o mediante email a la siguiente dirección de correo electrónico: in...@thecloud.es La información incluida en este e-mail es CONFIDENCIAL, siendo para uso exclusivo del destinatario arriba mencionado. Si usted lee este mensaje y no es el destinatario indicado, le informamos que está totalmente prohibida cualquier utilización, divulgación, distribución y/o reproducción de esta comunicación sin autorización expresa en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos nos lo notifique inmediatamente por esta misma vía y proceda a su eliminación. "
nubbius" es una marca registrada por The Cloud Gate S.L.

This information is private and confidential and intended for the recipient only. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an official statement from The Cloud Gate, S.L. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. 
"nubbius" is a registered trademark of The Cloud Gate S.L.
Reply all
Reply to author
Forward
0 new messages