For services requiring permission, such as write operations or browsing friends, the client must be authorized through OAuth.
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_tokenNext, authorize by opening the authorization URL in a browser:
request_token.authorize_urlThen request an OAuth access token:
access_token = request_token.get_access_tokenFinally, initialize a Goodreads client with it:
goodreads_client = Goodreads.new(oauth_token: access_token)For more info, see the Goodreads documentation.
Get the ID of the user who authorized via OAuth:
goodreads_client.user_idGet 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 }