JSON parsing error in ruby client on Users.messages.attachments.get

408 views Asked by At

gem 'google-api-client', '~> 0.7.1'

using ruby google client to call https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get it is crashing after i get the result and call result.data

result.rb line 154

data = @request.api_method.response_schema.new(data)

throws JSON::ParseError

757: unexpected token at '"R0lGODlhigKjAOYAAG2Xd9js18jkx........="'

1

There are 1 answers

1
ztan On

The data field of the attachment is base64 encoded, if you want to access the data field, you should decode it first.

For example you can do the following:

attachment_data = result.data
attachment_json = JSON.parse(attachment_data.to_json())
mime_data = Base64.decode64(attachment_json['data'])

Or try:

mime_data = Base64.decode64(result.data['data']) 

You might also want to read this article about how to parse json correctlu.