Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. get client_id from foursquare by OAuth2 gem
  2. cli = OAuth2::Client.new('CLIENT_ID', :authorize_url => "/oauth2/authorize", :token_url => "/oauth2/access_token", :site => 'https://foursquare.com')
  3.        
  4. cli = OAuth2::Client.new(client_id, client_secret, :authorize_url => "/oauth2/authorize", :token_url => "/oauth2/access_token", :site => 'https://foursquare.com')
  5. cli.auth_code.authorize_url(:redirect_uri => "http://localhost:3000")
  6. token = cli.auth_code.get_token('authorization_code_value', :redirect_uri => "http://localhost:3000/person/index")
  7. response = token.get('api/resource', :params => {'query_foo' => 'bar'})
  8. response.class.name
  9.        
  10. 1. Client_id: this is a unique id assigned to your application you
  11.     create on any Oauth service provider or when you register you application.
  12.  
  13.  2. Secret_key:This is another part of Oauth communication which use to
  14.     Authenticate the  consumer i.e you application.
  15.        
  16. Redirect users who wish to authenticate to
  17.  
  18. https://foursquare.com/oauth2/authenticate
  19.     ?client_id=YOUR_CLIENT_ID
  20.     &response_type=code
  21.     &redirect_uri=YOUR_REGISTERED_REDIRECT_URI
  22.        
  23. https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE
  24.        
  25. Your server will make a request for
  26.  
  27. https://foursquare.com/oauth2/access_token
  28. ?client_id=YOUR_CLIENT_ID
  29. &client_secret=YOUR_CLIENT_SECRET
  30. &grant_type=authorization_code
  31. &redirect_uri=YOUR_REGISTERED_REDIRECT_URI
  32. &code=CODE
  33.        
  34. { access_token: ACCESS_TOKEN }