facebook-cli 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e73b653e961bb1c35903f400db8e71aa06d851e2
4
- data.tar.gz: 2ef15430d063b9304b261981dc9603ceb22affb6
3
+ metadata.gz: 60d9c30c9452a91ea1f4a0dba2cfe4dbdc5aacab
4
+ data.tar.gz: ae1e56f576696173b59041215d60adabe4a58f8d
5
5
  SHA512:
6
- metadata.gz: d34aed99693ee1f0a23aaba1bbfcc45535bf81f039f7783891118e8cb8c3c496a4ecee1412a74e3cd8a3230f8d8f0a05891f951e6c565cd886e44bbe44ac825e
7
- data.tar.gz: f20b080c1116bf8d9314671756051a769d614e6ac7bf65c7c1cdd1ad46383652bb690e218853a802f254866c5f60c6b1f30c3e287a2d110f77ebaafae3d52106
6
+ metadata.gz: 18895ae4f97d5bb7a7f7716c3b123a07c6de1acfec8e5ee9804569f3bc08bfc87d56a42069e688cbf50f9806b21180809c5bf9ab6cbbd6a1376ce0aee8380f0c
7
+ data.tar.gz: f924eb53d4120dfd9b5fd9020652cf0192d34c9f873654406ec6a45ed728bbcb007f84c2fc47d0bebd3380135b20ed81de94f82724820f1680812cfac1683593
@@ -16,7 +16,7 @@ program_desc "Facebook command line interface"
16
16
  version FBCLI::VERSION
17
17
 
18
18
  flag [:token], :desc => 'Provide Facebook access token', :required => false
19
- flag [:pages, :p], :desc => 'Max pages', :required => false, :type => Integer, :default_value => -1
19
+ flag [:pages, :p], :desc => 'Maximum number of pages of results to retrieve', :required => false, :type => Integer, :default_value => -1
20
20
 
21
21
  def link(path)
22
22
  "https://www.facebook.com/#{path}"
@@ -84,10 +84,16 @@ You must create and configure a Facebook application to interact with the Graph
84
84
 
85
85
  - Create a new application at: https://developers.facebook.com/apps
86
86
  - In the Settings tab:
87
- - Click "Add Platform" and select "Website"
88
- - Set "Site URL" to "http://localhost"
89
87
  - Under "App Domains" add "localhost"
90
- - Click "Save"
88
+ - Select a "Category" (any one will do)
89
+ - Click "Add Platform" and select "Website"
90
+ - Set "Site URL" to "http://localhost/"
91
+ - Click "Save Changes"
92
+ - Under "PRODUCTS" in the left sidebar:
93
+ - Click "+ Add Product"
94
+ - Under "Client OAuth Settings", set "Use Strict Mode for Redirect URIs" to "No"
95
+ - Under "Valid OAuth redirect URIs", add: "http://localhost:3333/"
96
+ - Click "Save Changes"
91
97
  - In the "App Review" tab:
92
98
  - Flip the switch to make your app live
93
99
  - In the "Dashboard" tab:
@@ -122,33 +128,58 @@ command :config do |c|
122
128
  end
123
129
 
124
130
  desc "Request Facebook permissions and receive an API access token"
131
+ long_desc %(
132
+ Print a URL that launches a request to Facebook to allow the app you've created (by
133
+ following the setup instructions) to perform Facebook Graph actions on your behalf,
134
+ and start an HTTP server to listen for the authorization code.
135
+
136
+ Upon receiving the authorization code, immediately trade it in for an access
137
+ token and save it to a configuration file.
138
+
139
+ See: https://www.oauth.com/oauth2-servers/access-tokens/
140
+
141
+ Attention: if you choose to listen for the authorization token on a port number
142
+ different from the default value, make sure that in your app settings the same
143
+ port is specified under:
144
+
145
+ PRODUCTS > Facebook Login > Client OAuth Settings > Valid OAuth redirect URIs
146
+ )
125
147
  command :login do |c|
126
- c.flag [:port], :desc => 'Local TCP port to serve Facebook login redirect page', :default_value => '3333'
148
+ c.flag [:port], :desc => 'Local TCP port to listen for authorization code', :default_value => '3333'
127
149
  c.switch [:info], :desc => 'Show information about the current access token and exit', :negatable => false
128
150
  c.action do |global_options, options|
129
151
  if options['info']
130
- begin
131
- FBCLI::request_token_info do |data|
132
- puts "Your access token was issued on: #{date_str(data['issued_at'])}"
133
- puts
134
- puts "It is valid until: #{date_str(data['expires_at'])}"
152
+ if $config['access_token'].nil?
153
+ puts "Either provide an access token via the --token parameter or obtain one by running:"
154
+ puts
155
+ puts " #{APP_NAME} login"
156
+ else
157
+ begin
158
+ puts "Your access token: #{$config['access_token']}"
135
159
  puts
136
- puts "Permissions:\n - #{data['scopes'].join("\n - ")}"
160
+
161
+ FBCLI::request_token_info do |data|
162
+ puts "It was issued on: #{date_str(data['issued_at'])}"
163
+ puts
164
+ puts "It is valid until: #{date_str(data['expires_at'])}"
165
+ puts
166
+ puts "Permissions:\n - #{data['scopes'].join("\n - ")}"
167
+ end
168
+ rescue
169
+ puts "Your access token does not appear to be valid or may have expired."
137
170
  end
138
- rescue
139
- puts "Your access token does not appear to be valid for this application."
140
171
  end
141
172
  else
142
- token = FBCLI::listen_for_auth_code(options['port'], $config['app_id'], $config['app_secret'])
173
+ token = FBCLI::login($config['app_id'], $config['app_secret'], options['port'])
143
174
 
144
175
  if not token.nil?
145
176
  $config['access_token'] = token
146
177
 
147
178
  save_config
148
179
 
149
- puts "Your access token: #{token}"
180
+ puts "Your access token has been saved to #{CONFIG_FILE}"
150
181
  puts
151
- puts "To find out when it is scheduled to expire, run:"
182
+ puts "To see it and find out when it is scheduled to expire, run:"
152
183
  puts
153
184
  puts " #{APP_NAME} login --info"
154
185
  puts
@@ -6,9 +6,11 @@ require 'json'
6
6
  module FBCLI
7
7
  API_VERSION = "2.10"
8
8
 
9
- def self.listen_for_auth_code(port, app_id, app_secret)
9
+ def self.login(app_id, app_secret, local_port)
10
+ redirect_uri = "http://localhost:#{local_port}/"
11
+
10
12
  uri = "https://www.facebook.com/dialog/oauth?client_id=#{app_id}" +
11
- "&redirect_uri=http://localhost:#{port}/" +
13
+ "&redirect_uri=#{redirect_uri}" +
12
14
  "&scope=user_likes,user_friends,user_posts,user_photos,user_videos,user_events,publish_actions"
13
15
 
14
16
  puts <<-EOM
@@ -16,12 +18,12 @@ Open this URL in a web browser and allow access to the Facebook Graph on behalf
16
18
 
17
19
  #{uri}
18
20
 
19
- Waiting to receive authorization code on port #{port}...
21
+ Waiting to receive authorization code on port #{local_port}...
20
22
 
21
23
  EOM
22
24
 
23
25
  server = WEBrick::HTTPServer.new(
24
- :Port => port,
26
+ :Port => local_port,
25
27
  :SSLEnable => false,
26
28
  :Logger => WEBrick::Log.new(File.open(File::NULL, 'w')),
27
29
  :AccessLog => []
@@ -33,7 +35,10 @@ Waiting to receive authorization code on port #{port}...
33
35
  key, value = req.query_string.split '=', 2
34
36
 
35
37
  if key == "code"
36
- access_token = get_access_token(port, app_id, value, app_secret)
38
+ puts "Received authorization code. Exchanging it for an access token..."
39
+ puts
40
+
41
+ access_token = get_access_token(app_id, value, app_secret, redirect_uri)
37
42
  else
38
43
  puts "Received unexpected request: #{req.query_string}"
39
44
  end
@@ -52,10 +57,15 @@ Waiting to receive authorization code on port #{port}...
52
57
  access_token
53
58
  end
54
59
 
55
- def self.get_access_token(port, app_id, auth_code, app_secret)
60
+ def self.get_access_token(app_id, auth_code, app_secret, redirect_uri)
61
+ # The redirect_uri doesn't play the same role as in capturing the auth code, however
62
+ # it must match the one used in the previous case, otherwise the server will reject
63
+ # the request.
64
+ #
65
+ # See: https://www.oauth.com/oauth2-servers/access-tokens/authorization-code-request/
56
66
  auth_uri = "https://graph.facebook.com/v#{API_VERSION}/oauth/access_token?" +
57
67
  "client_id=#{app_id}" +
58
- "&redirect_uri=http://localhost:#{port}/" +
68
+ "&redirect_uri=#{redirect_uri}" +
59
69
  "&client_secret=#{app_secret}" +
60
70
  "&code=#{auth_code}"
61
71
 
@@ -48,9 +48,9 @@ Run: #{APP_NAME} login
48
48
  }
49
49
  end
50
50
 
51
- def self.request_token_info
51
+ def self.request_token_info(access_token = $config['access_token'])
52
52
  api_call lambda { |api|
53
- api.debug_token $config['access_token'] do |res|
53
+ api.debug_token access_token do |res|
54
54
  yield res['data']
55
55
  end
56
56
  }
@@ -1,3 +1,3 @@
1
1
  module FBCLI
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ildar Sagdejev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2017-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: koala