ruby-on-railsrubypicasagoogle-photos

743: unexpected token at '‹' happens using picasa gem in ruby on rails


I want to get pictures from google photo using Picasa Web Album Data API on ruby on rails web application.

However, the error that

JSON::ParserError in PhotosController#photo 743: unexpected token at '‹'

has happend at the code @album_list= client.album.list

the source code is here.

require 'signet/oauth_2/client'
require 'google/apis'
require 'picasa'

class PhotosController < ApplicationController

  def photo
    client = Picasa::Client.new(user_id: "hoge@gmail.com", access_token: get_access_token)
    @album_list = client.album.list


  end

  private

    def get_access_token
      signet = Signet::OAuth2::Client.new(
        authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
        client_id: Rails.application.secrets.google[:api][:client_id],
        client_secret: Rails.application.secrets.google[:api][:client_secret],
        token_credential_uri: "https://www.googleapis.com/oauth2/v3/token",
        scope: 'email profile',
        refresh_token: Rails.application.secrets.google[:api][:refresh_token]
      )
      signet.refresh!
      signet.access_token                
    end     

end

I think that client.album.list retruns not json but xml. However, picasa gem expects the json format...

the versions are

signet (0.8.1)
google-api-client (0.19.8)
googleauth (0.6.2)
picasa (0.9.1)
Rails 5.1.5
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

How do I solve this problem?

Sorry my poor English. Please tell me the missing information.


Solution

  • There's an issue on their github page about this. I think the gem hasn't been updated in a little while, but the person who raised the issue includes the following fix:

      Picasa::HTTP.instance_variable_get(:@default_options)[:headers]['User-Agent'].sub!(/ \(gzip\)/, '')
    

    you cann put this in config/initializers/picasa.rb