From 105510adf25a9d821761e9f945ef2cb534f90607 Mon Sep 17 00:00:00 2001 From: sgomes Date: Fri, 9 Aug 2013 14:40:39 +0100 Subject: [PATCH] Updating README to use best practices in usage example --- README.md | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d381870bc..ac77f4ad0 100644 --- a/README.md +++ b/README.md @@ -28,26 +28,33 @@ $ gem install google-api-client ## Example Usage ```ruby -# Initialize the client & Google+ API require 'google/api_client' -client = Google::APIClient.new +require 'google/api_client/client_secrets' + +# Initialize the client. +client = Google::APIClient.new( + :application_name => 'Example Ruby application', + :application_version => '1.0.0' +) + +# Initialize Google+ API. Note this will make a request to the +# discovery service every time, so be sure to use serialization +# in your production code. Check the samples for more details. plus = client.discovered_api('plus') -# Initialize OAuth 2.0 client -client.authorization.client_id = '' -client.authorization.client_secret = '' -client.authorization.redirect_uri = '' +# Load client secrets from your client_secrets.json. +client_secrets = Google::APIClient::ClientSecrets.load -client.authorization.scope = 'https://www.googleapis.com/auth/plus.me' +# Run installed application flow. Check the samples for a more +# complete example that saves the credentials between runs. +flow = Google::APIClient::InstalledAppFlow.new( + :client_id => client_secrets.client_id, + :client_secret => client_secrets.client_secret, + :scope => ['https://www.googleapis.com/auth/plus.me'] +) +client.authorization = flow.authorize(file_storage) -# 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( :api_method => plus.activities.list, :parameters => {'collection' => 'public', 'userId' => 'me'}