Skip to content

Commit c4993ad

Browse files
madeleinelsimi
authored andcommitted
Upgrade Facebook Graph API to 4.0
The current Facebook Graph API version (v3.0) was only available until 28 July, 2020. This commit upgrades it to v4.0. ---- Version 4.0 Released July 29, 2019 | Available until November 2nd, 2021 https://developers.facebook.com/docs/graph-api/changelog/version4.0
1 parent 48cdde2 commit c4993ad

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 7.0.0 (2020-08-03)
2+
3+
Changes:
4+
5+
- bumped version of FB Graph API to v4.0
6+
17
## 6.0.0 (2020-01-27)
28

39
Changes:

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ end
5858

5959
### API Version
6060

61-
OmniAuth Facebook uses versioned API endpoints by default (current v3.0). You can configure a different version via `client_options` hash passed to `provider`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v4.0 (assuming that exists):
61+
OmniAuth Facebook uses versioned API endpoints by default (current v4.0). You can configure a different version via `client_options` hash passed to `provider`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v7.0 (assuming that exists):
6262

6363
```ruby
6464
use OmniAuth::Builder do
6565
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
6666
client_options: {
67-
site: 'https://graph.facebook.com/v4.0',
68-
authorize_url: "https://www.facebook.com/v4.0/dialog/oauth"
67+
site: 'https://graph.facebook.com/v7.0',
68+
authorize_url: "https://www.facebook.com/v7.0/dialog/oauth"
6969
}
7070
end
7171
```

example/app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
window.fbAsyncInit = function() {
3030
FB.init({
3131
appId: '#{ENV['FACEBOOK_APP_ID']}',
32-
version: 'v3.0',
32+
version: 'v4.0',
3333
cookie: true // IMPORTANT must enable cookies to allow the server to access the session
3434
});
3535
console.log("fb init");

lib/omniauth/facebook/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module OmniAuth
22
module Facebook
3-
VERSION = '6.0.0'
3+
VERSION = '7.0.0'
44
end
55
end

lib/omniauth/strategies/facebook.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class NoAuthorizationCodeError < StandardError; end
1212
DEFAULT_SCOPE = 'email'
1313

1414
option :client_options, {
15-
site: 'https://graph.facebook.com/v3.0',
16-
authorize_url: "https://www.facebook.com/v3.0/dialog/oauth",
15+
site: 'https://graph.facebook.com/v4.0',
16+
authorize_url: "https://www.facebook.com/v4.0/dialog/oauth",
1717
token_url: 'oauth/access_token'
1818
}
1919

test/strategy_test.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class StrategyTest < StrategyTestCase
99

1010
class ClientTest < StrategyTestCase
1111
test 'has correct Facebook site' do
12-
assert_equal 'https://graph.facebook.com/v3.0', strategy.client.site
12+
assert_equal 'https://graph.facebook.com/v4.0', strategy.client.site
1313
end
1414

1515
test 'has correct authorize url' do
16-
assert_equal 'https://www.facebook.com/v3.0/dialog/oauth', strategy.client.options[:authorize_url]
16+
assert_equal 'https://www.facebook.com/v4.0/dialog/oauth', strategy.client.options[:authorize_url]
1717
end
1818

1919
test 'has correct token url with versioning' do
@@ -99,7 +99,7 @@ class InfoTest < StrategyTestCase
9999
@options = { secure_image_url: true }
100100
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
101101
strategy.stubs(:raw_info).returns(raw_info)
102-
assert_equal 'https://graph.facebook.com/v3.0/321/picture', strategy.info['image']
102+
assert_equal 'https://graph.facebook.com/v4.0/321/picture', strategy.info['image']
103103
end
104104

105105
test 'returns the image_url based of the client site' do
@@ -113,14 +113,14 @@ class InfoTest < StrategyTestCase
113113
@options = { image_size: 'normal' }
114114
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
115115
strategy.stubs(:raw_info).returns(raw_info)
116-
assert_equal 'http://graph.facebook.com/v3.0/321/picture?type=normal', strategy.info['image']
116+
assert_equal 'http://graph.facebook.com/v4.0/321/picture?type=normal', strategy.info['image']
117117
end
118118

119119
test 'returns the image with size specified as a symbol in the `image_size` option' do
120120
@options = { image_size: :normal }
121121
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
122122
strategy.stubs(:raw_info).returns(raw_info)
123-
assert_equal 'http://graph.facebook.com/v3.0/321/picture?type=normal', strategy.info['image']
123+
assert_equal 'http://graph.facebook.com/v4.0/321/picture?type=normal', strategy.info['image']
124124
end
125125

126126
test 'returns the image with width and height specified in the `image_size` option' do
@@ -129,7 +129,7 @@ class InfoTest < StrategyTestCase
129129
strategy.stubs(:raw_info).returns(raw_info)
130130
assert_match 'width=123', strategy.info['image']
131131
assert_match 'height=987', strategy.info['image']
132-
assert_match 'http://graph.facebook.com/v3.0/321/picture?', strategy.info['image']
132+
assert_match 'http://graph.facebook.com/v4.0/321/picture?', strategy.info['image']
133133
end
134134
end
135135

@@ -176,7 +176,7 @@ def setup
176176

177177
test 'returns the facebook avatar url' do
178178
@raw_info['id'] = '321'
179-
assert_equal 'http://graph.facebook.com/v3.0/321/picture', strategy.info['image']
179+
assert_equal 'http://graph.facebook.com/v4.0/321/picture', strategy.info['image']
180180
end
181181

182182
test 'returns the Facebook link as the Facebook url' do
@@ -258,15 +258,15 @@ def setup
258258
@options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
259259
end
260260

261-
test 'performs a GET to https://graph.facebook.com/v3.0/me' do
261+
test 'performs a GET to https://graph.facebook.com/v4.0/me' do
262262
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
263263
strategy.stubs(:access_token).returns(@access_token)
264264
params = {params: @options}
265265
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
266266
strategy.raw_info
267267
end
268268

269-
test 'performs a GET to https://graph.facebook.com/v3.0/me with locale' do
269+
test 'performs a GET to https://graph.facebook.com/v4.0/me with locale' do
270270
@options.merge!({ locale: 'cs_CZ' })
271271
strategy.stubs(:access_token).returns(@access_token)
272272
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
@@ -275,7 +275,7 @@ def setup
275275
strategy.raw_info
276276
end
277277

278-
test 'performs a GET to https://graph.facebook.com/v3.0/me with info_fields' do
278+
test 'performs a GET to https://graph.facebook.com/v4.0/me with info_fields' do
279279
@options.merge!({info_fields: 'about'})
280280
strategy.stubs(:access_token).returns(@access_token)
281281
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
@@ -284,7 +284,7 @@ def setup
284284
strategy.raw_info
285285
end
286286

287-
test 'performs a GET to https://graph.facebook.com/v3.0/me with default info_fields' do
287+
test 'performs a GET to https://graph.facebook.com/v4.0/me with default info_fields' do
288288
strategy.stubs(:access_token).returns(@access_token)
289289
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
290290
params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}

0 commit comments

Comments
 (0)