2011-10-06 08:48:53 +00:00
|
|
|
# APIClient
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
<dl>
|
|
|
|
<dt>Homepage</dt><dd><a href="http://code.google.com/p/google-api-ruby-client">http://code.google.com/p/google-api-ruby-client</a></dd>
|
|
|
|
<dt>Author</dt><dd><a href="mailto:bobaman@google.com">Bob Aman</a></dd>
|
|
|
|
<dt>Copyright</dt><dd>Copyright © 2011 Google, Inc.</dd>
|
|
|
|
<dt>License</dt><dd>Apache 2.0</dd>
|
|
|
|
</dl>
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2012-05-11 10:16:38 +00:00
|
|
|
[![Build Status](https://secure.travis-ci.org/google/google-api-ruby-client.png)](http://travis-ci.org/google/google-api-ruby-client)
|
|
|
|
[![Dependency Status](https://gemnasium.com/google/google-api-ruby-client.png)](https://gemnasium.com/google/google-api-ruby-client)
|
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
# Description
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2010-10-07 00:02:22 +00:00
|
|
|
The Google API Ruby Client makes it trivial to discover and access supported
|
|
|
|
APIs.
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
# Example Usage
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2012-09-24 22:21:56 +00:00
|
|
|
# Initialize the client & Google+ API
|
2011-10-06 08:48:53 +00:00
|
|
|
require 'google/api_client'
|
2012-09-24 22:21:56 +00:00
|
|
|
client = Google::APIClient.new
|
|
|
|
plus = client.discovered_api('plus')
|
|
|
|
|
|
|
|
# Initialize OAuth 2.0 client
|
|
|
|
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'
|
2011-10-06 08:48:53 +00:00
|
|
|
|
2012-09-24 22:21:56 +00:00
|
|
|
# Request authorization
|
|
|
|
redirect_uri = client.authorization.authorization_uri
|
|
|
|
|
|
|
|
# Wait for authorization code then exchange for token
|
|
|
|
client.authorization.code = '....'
|
|
|
|
client.authorization.fetch_access_token!
|
2011-10-06 08:48:53 +00:00
|
|
|
|
|
|
|
# Make an API call
|
2012-01-27 14:57:57 +00:00
|
|
|
result = client.execute(
|
2012-09-24 22:21:56 +00:00
|
|
|
:api_method => plus.activities.list'
|
|
|
|
:parameters => {'collection' => 'public', 'userId' => 'me'}
|
2011-10-06 08:48:53 +00:00
|
|
|
)
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2012-09-24 22:21:56 +00:00
|
|
|
puts result.data
|
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
# Install
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
Be sure `http://rubygems.org/` is in your gem sources.
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2010-10-14 00:04:36 +00:00
|
|
|
For normal client usage, this is sufficient:
|
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
$ sudo gem install google-api-client
|
2010-10-14 00:04:36 +00:00
|
|
|
|
|
|
|
The command line interface, the example applications, and the test suite
|
|
|
|
require additional dependencies. These may be obtained with:
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2011-10-06 08:48:53 +00:00
|
|
|
$ sudo gem install google-api-client --development --force --no-rdoc --no-ri
|