Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.1 KB

oauth.md

File metadata and controls

57 lines (38 loc) · 1.1 KB

Authorizing Goodreads via OAuth

For services requiring permission, such as write operations or browsing friends, the client must be authorized through OAuth.

Request Tokens vs. Access Tokens

First, get an OAuth request token:

request_token = OAuth::Consumer.new(
  Goodreads.configuration[:api_key],
  Goodreads.configuration[:api_secret],
  site: "http://www.goodreads.com"
).get_request_token

Next, authorize by opening the authorization URL in a browser:

request_token.authorize_url

Then request an OAuth access token:

access_token = request_token.get_access_token

Finally, initialize a Goodreads client with it:

goodreads_client = Goodreads.new(oauth_token: access_token)

For more info, see the Goodreads documentation.

User ID

Get the ID of the user who authorized via OAuth:

goodreads_client.user_id

Friends

Get the friend details for a user:

friends_hash = goodreads_client.friends [user_id]

Get a list of their names:

friends_hash.user.map{ |u| u.name }