I have response from Gmail API encoded in base64.
I used com.google.api.client.util.Base64
to decode this response, and it worked fine.
Now I'm refactoring code and want to update versions of dependencies. I noticed that Base64 class is now deprecated and it's suggested to use com.google.common.io.BaseEncoding
. However, when I do the following:
Message asdf = service.users().messages().get(gmailUser, message.getId()).execute();
List<MessagePartHeader> headers = asdf.getPayload().getHeaders();
String data = asdf.getPayload().getBody().getData();
String body = new String(BaseEncoding.base64().decode(data));
I get an error:
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException: com.google.common.io.BaseEncoding$DecodingException: Unrecognized character: -
And indeed, I have some dashes in data that I'm receiving.
Is this a bug in Gmail API? Is there a workaround for that?
Got it!
I shouldn't use BaseEncoding.base64().decode(data)
, but BaseEncoding.base64Url().decode(data)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With