【问题标题】:743: unexpected token at '‹' happens using picasa gem in ruby on rails743:在 '‹' 出现意外标记在 ruby​​ on rails 中使用 picasa gem
【发布时间】:2018-02-26 13:48:41
【问题描述】:

我想在 ruby​​ on rails 网络应用程序上使用 Picasa 网络相册数据 API 从谷歌照片中获取图片。

但是,错误提示

PhotosController#photo 中的 JSON::ParserError 743:“‹”处的意外标记

发生在代码@album_list= client.album.list

源代码在这里。

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

我认为client.album.list 返回的不是 json 而是 xml。 但是,picasa gem 需要 json 格式...

版本是

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]

我该如何解决这个问题?

对不起,我的英语不好。 请告诉我缺少的信息。

【问题讨论】:

    标签: ruby-on-rails ruby picasa google-photos


    【解决方案1】:

    在他们的 github 页面上有一个 issue 与此有关。我认为 gem 已经有一段时间没有更新了,但是提出问题的人包括以下修复:

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

    你不能把这个放在config/initializers/picasa.rb

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      相关资源
      最近更新 更多