sosedoff / goodreads

Goodreads API wrapper

Home Page:https://www.goodreads.com/api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OAuth - getting access token for existing user

niyando opened this issue · comments

Not really an issue related to this wrapper, but I need some help regarding oauth. I am following the example given on https://github.com/sosedoff/goodreads/blob/master/examples/oauth.md

Once I get a hold of the access_token (the token value), I store it in the database. I would like the same token to be used after connecting with goodreads.

However, following snippet doesn't accept access_token as a string. It expects it to be an instance of OAuth::AccessToken.
goodreads_client = Goodreads.new(oauth_token: access_token)

How do I generate the access_token instance for such existing users?
Thanks,

Can you initialize it like this?

token = OAuth::AccessToken.new("foo"
# => #<OAuth::AccessToken:0x007f956a3978d8 @token="", @secret="", @consumer="foo", @params={}>

client = Goodreads.new(oauth_token: token)

Havent tried that, but i assume it'll be somewhat similar.

@sosedoff, eventually figured this out. You're right. The idea is to persist the token and secret somewhere (session and db combination) and use it in the subsequent requests to generate the access token instance OAuth::AccessToken.

Thank you.