いつもお世話になっております。
Google APIを使って、カレンダー登録を行ないたいと考えているのですが
下記のエラーが生じてしまい次に進むことができません。
具体的には、認証時に取得したgoogle-api-token
と名付けたレコードをclient
に挿入しようと試みているのですがうまくいっていないという状況です。
参考URL:
https://qiita.com/yosidadada/items/083a05c8e4465baee98e
NoMethodError: undefined method `each' for #<String:0x00007fd25059bb70> from /Users/sy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/signet-0.10.0/lib/signet/oauth_2/client.rb:1182:in `deep_hash_normalize'
ソースコードは下記のイベント登録時に呼ぶ際に起きているアクションとなります。
ruby
1 def create_event 2 client = Signet::OAuth2::Client.new(CLIENT_OPTIONS) 3 binding.pry 4 # ここでエラーがおきる(updateできない) 5 client.update!(user.google_api_token) 6 service = Google::Apis::CalendarV3::CalendarService.new 7 service.authorization = client 8 service.insert_event(user.calendar_id, calendar_event) 9 rescue Google::Apis::AuthorizationError 10 refresh_token 11 retry 12 end
client
の中身は取れています。
@additional_parameters={:prompt=>"consent"}, @authorization_uri=#<Addressable::URI:XXXXXXXXXXXXXXXXXXX URI:https://accounts.google.com/o/oauth2/auth>, @client_id="XXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com", @client_secret="XXXXXXXXXXXXXXXXXXX", @code=nil, @expires_at=nil, @expiry=60, @extension_parameters={}, @issued_at=nil, @issuer=nil, @password=nil, @principal=nil, @redirect_uri=#<Addressable::URI:XXXXXXXXXXXXXXXXXXX URI:XXXXXXXXXXXXXXXXXXX>, @scope=["https://www.googleapis.com/auth/calendar"], @state=nil, @token_credential_uri=#<Addressable::URI:XXXXXXXXXXXXXXXXXXX URI:https://www.googleapis.com/oauth2/v4/token>, @username=nil>
user.google_api_token
の中身も取れています。
=> "{\n \"access_token\": \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n \"expires_in\": 3600,\n \"refresh_token\": \"4/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n \"scope\": \"https://www.googleapis.com/auth/calendar\",\n \"token_type\": \"Bearer\"\n}"
Qiita記事と異なるのが、Qiita記事が下記のテキスト形式で取得しているのに対して、私はjson形式で保存しています。
これが原因となっているのでしょうか。
Qiita記事
Ruby
1--- 2 access_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 3 expires_in: 3600 4 refresh_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 scope: https://www.googleapis.com/auth/calendar 6 token_type: Bearer
こちらの環境
{ "access_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "expires_in": 3600, "refresh_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "scope": "https://www.googleapis.com/auth/calendar", "token_type": "Bearer" }
また、Userモデルもエラーが出てしまうため一部変更しています。
serialize :google_api_token, Hash
上記を排除しています。
すみませんが、ご助言いただければと思います!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/11 03:29