Class: Facebook
- Inherits:
-
Object
- Object
- Includes:
- HTTParty
- Defined in:
- lib/generators/horse_power/user/templates/facebook.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_long_token(short_token) ⇒ Object
- #get_user_id(token) ⇒ Object
-
#initialize ⇒ Facebook
constructor
format :json debug_output $stdout.
Constructor Details
#initialize ⇒ Facebook
format :json debug_output $stdout
9 10 |
# File 'lib/generators/horse_power/user/templates/facebook.rb', line 9 def initialize() end |
Class Method Details
.get_id(fb_api, long_token, short_token) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/horse_power/user/templates/facebook.rb', line 38 def self.get_id(fb_api,long_token,short_token) response = fb_api.get_user_id(long_token) if response.code == 200 @token = long_token return JSON.parse(response.body)["id"] end #Lets try it with the short token now response = fb_api.get_user_id(short_token) if response.code == 200 @token = short_token return JSON.parse(response.body)["id"] end return nil end |
Instance Method Details
#get_long_token(short_token) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/generators/horse_power/user/templates/facebook.rb', line 12 def get_long_token(short_token) params = { grant_type: "fb_exchange_token", client_id: ENV["FB_APP_ID1"], client_secret: ENV["FB_APP_SECRET1"], fb_exchange_token: short_token } headers = { 'Content-Type' => 'application/json' } response = self.class.get("/oauth/access_token", query: params, headers: headers) if response.code == 200 return parse_token(response.body) else return "" end end |
#get_user_id(token) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/horse_power/user/templates/facebook.rb', line 28 def get_user_id(token) = { query:{ fields: "id", access_token: token } } response = self.class.get("/me", ) return response end |