Class: FbGraph::Application

Instance Attribute Summary collapse

Attributes inherited from Node

#access_token, #endpoint, #identifier

Instance Method Summary collapse

Methods included from Connections::Insights

#insights

Methods included from Connections::Subscriptions

#subscribe!, #subscriptions, #unsubscribe!

Methods included from Connections::Events

#event!, #events

Methods included from Connections::Notes

#note!, #notes

Methods included from Connections::Videos

#videos

Methods included from Connections::Statuses

#statuses

Methods included from Connections::Albums

#album!, #albums

Methods included from Connections::Photos

#photo!, #photos

Methods included from Connections::Links

#link!, #links

Methods included from Connections::Tagged

#tagged

Methods included from Connections::Picture

#picture

Methods included from Connections::Posts

#posts

Methods included from Connections::Feed

#feed, #feed!

Methods inherited from Node

#connection, #destroy, fetch, #fetch

Methods included from Comparison

#==

Constructor Details

#initialize(client_id, attributes = {}) ⇒ Application

Returns a new instance of Application.



19
20
21
22
23
24
25
26
# File 'lib/fb_graph/application.rb', line 19

def initialize(client_id, attributes = {})
  super
  @name         = attributes[:name]
  @description  = attributes[:description]
  @category     = attributes[:category]
  @link         = attributes[:link]
  @secret       = attributes[:secret]
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



17
18
19
# File 'lib/fb_graph/application.rb', line 17

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



17
18
19
# File 'lib/fb_graph/application.rb', line 17

def description
  @description
end

Returns the value of attribute link.



17
18
19
# File 'lib/fb_graph/application.rb', line 17

def link
  @link
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/fb_graph/application.rb', line 17

def name
  @name
end

#secretObject

Returns the value of attribute secret.



17
18
19
# File 'lib/fb_graph/application.rb', line 17

def secret
  @secret
end

Instance Method Details

#get_access_token(secret = nil) ⇒ Object

Get OAuth access token

Obtain an OAuth access token associated with your application via the OAuth Client Credentials Flow.

ref) developers.facebook.com/docs/api#analytics

app = FbGraph::Application.new(APP_ID)
app.get_access_token
# => access token as String
app.access_token # once get_access_token is called, access token is cached.
# => access token as String

This method is automatically called when access token needed and application secret has already given.

app = FbGraph::Application.new(APP_ID, :secret => APP_SECRET)
app.subscriptions # get_access_token is called automatically
# => Array of FbGraph::Subscription


45
46
47
48
49
50
51
52
53
54
# File 'lib/fb_graph/application.rb', line 45

def get_access_token(secret = nil)
  self.secret ||= secret
  auth = FbGraph::Auth.new(self.identifier, self.secret)
  response_string = auth.client.request(:post, auth.client.access_token_url, {
    :client_id => self.identifier,
    :client_secret => self.secret,
    :type => 'client_cred'
  })
  self.access_token = response_string.split('=').last
end