Closed migu0 closed 10 years ago
(Note, I didn't test this too much, it's from memory).
Make sure your app is set up properly, and that you've enabled the Contacts API in the Google Developers Console at https://console.developers.google.com/project. Then try this:
CLIENT_ID = '?????.apps.googleusercontent.com'
CLIENT_SECRET = 'your_secret'
REDIRECT_URI = 'url_you_registered_with_google'
client = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET,
site: 'https://accounts.google.com',
token_url: '/o/oauth2/token',
authorize_url: '/o/oauth2/auth')
url = client.auth_code.authorize_url(scope: "https://www.google.com/m8/feeds",
redirect_uri: REDIRECT_URI)
Then visit url
in your browser and log in to Google. The url you are redirected to afterwards will contain the token in the parameter code
. It will look like this (not actual code to run, just an interpolation example):
redirect_url = "#{REDIRECT_URI}?code=#{code}"
Parse the code from the redirect url, then construct an API client as I describe in the docs.
token = client.auth_code.get_token(code, :redirect_uri => REDIRECT_URI)
google_contacts_user = GoogleContactsApi::User.new(token)
Since I haven't heard back from you I'm going to close this issue
Thanks Aliang for explaining and closing the issue. Sorry for late reply, I'm on a holiday.
Awesome gem, thanks a lot for your hard work.
I struggle to connect through oAuth, would you mind giving detailed step by step instructions on what to do to obtain the oauth_access_token_for_user?