Update example in readme

This commit is contained in:
Steven Bazyl 2012-09-24 15:21:56 -07:00
parent 4665331502
commit c58b350212
1 changed files with 18 additions and 33 deletions

View File

@ -17,46 +17,31 @@ APIs.
# Example Usage # Example Usage
# Initialize the client # Initialize the client & Google+ API
require 'google/api_client' require 'google/api_client'
require 'signet/oauth_1/client' client = Google::APIClient.new
client = Google::APIClient.new( plus = client.discovered_api('plus')
:service => 'buzz',
# Buzz has API-specific endpoints
:authorization => Signet::OAuth1::Client.new(
:temporary_credential_uri =>
'https://www.google.com/accounts/OAuthGetRequestToken',
:authorization_uri =>
'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken',
:token_credential_uri =>
'https://www.google.com/accounts/OAuthGetAccessToken',
:client_credential_key => 'anonymous',
:client_credential_secret => 'anonymous'
)
)
client.authorization.fetch_temporary_credential!(
:additional_parameters => {
'scope' => 'https://www.googleapis.com/auth/buzz'
}
)
redirect_uri = client.authorization.authorization_uri(
:additional_parameters => {
'domain' => client.authorization.client_credential_key,
'scope' => 'https://www.googleapis.com/auth/buzz'
}
)
# Redirect user here
client.authorization.fetch_token_credential!(:verifier => '12345')
# Discover available methods # Initialize OAuth 2.0 client
method_names = client.discovered_api('plus').to_h.keys client.authorization.client_id = '<CLIENT_ID_FROM_API_CONSOLE>'
client.authorization.client_secret = '<CLIENT_SECRET>'
client.authorization.scope = 'https://www.googleapis.com/auth/plus.me'
# Request authorization
redirect_uri = client.authorization.authorization_uri
# Wait for authorization code then exchange for token
client.authorization.code = '....'
client.authorization.fetch_access_token!
# Make an API call # Make an API call
result = client.execute( result = client.execute(
'plus.activities.list', :api_method => plus.activities.list'
{'collection' => 'public', 'userId' => 'me'} :parameters => {'collection' => 'public', 'userId' => 'me'}
) )
puts result.data
# Install # Install
Be sure `http://rubygems.org/` is in your gem sources. Be sure `http://rubygems.org/` is in your gem sources.