Sha256: 81326d9c9f37b5ac3e9921ba2df890f3683de97237b3a602297614402d4832f8
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
require 'httparty' class Facebook include ::HTTParty base_uri 'https://graph.facebook.com/v2.1' #format :json #debug_output $stdout def initialize() end 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 def get_user_id(token) options = { query:{ fields: "id", access_token: token } } response = self.class.get("/me", options) return response end private def parse_token(response) #access_token={access-token}&expires={seconds-til-expiration} index = response.index('&') start_index = "access_token=".size length = index - start_index return response.slice(start_index,length) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
horse_power-0.1.1 | lib/generators/horse_power/user/templates/facebook.rb |
horse_power-0.1.0 | lib/generators/horse_power/user/templates/facebook.rb |