我想在 ruby on rails 网络应用程序上使用 Picasa 网络相册数据 API 从 google photo 获取图片。
但是,错误是
JSON::PhotosController 中的 ParserError#photo 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]
我该如何解决这个问题?
对不起我糟糕的英语。 请告诉我缺少的信息。
最佳答案
有一个 issue在他们关于这个的github页面上。我认为 gem 已经有一段时间没有更新了,但是提出问题的人包括以下修复:
Picasa::HTTP.instance_variable_get(:@default_options)[:headers]['User-Agent'].sub!(/ \(gzip\)/, '')
你可以把它放在config/initializers/picasa.rb
关于ruby-on-rails - 743 : unexpected token at '‹' happens using picasa gem in ruby on rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48990055/