Sha256: 67407fad0d9f471d0b7bab8966cf3c13ed895dab664325ebf74f36df656c2e8d

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# 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:

```ruby
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:

```ruby
request_token.authorize_url
```

Then request an OAuth *access* token:

```ruby
access_token = request_token.get_access_token
```

Finally, initialize a Goodreads client with it:

```ruby
goodreads_client = Goodreads.new :oauth_token => access_token
```

For more info, see the [Goodreads documentation](http://www.goodreads.com/api/oauth_example).

## User ID

Get the ID of the user who authorized via OAuth:

```ruby
goodreads_client.user_id
```

## Friends

Get the friend details for a user:

```ruby
friends_hash = goodreads_client.friends [user_id]
```

Get a list of their names:

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
goodreads-0.4.3 examples/oauth.md
goodreads-0.4.2 examples/oauth.md
goodreads-0.4.1 examples/oauth.md
goodreads-0.4.0 examples/oauth.md
goodreads-0.3.0 examples/oauth.md
goodreads_17up-0.2.2 examples/oauth.md
goodreads-0.2.2 examples/oauth.md
goodreads_17up-0.2.1 examples/oauth.md