Skip to content

Commit ba8944a

Browse files
committed
Update to reflect new OAuth cookie name
1 parent b2da20f commit ba8944a

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

examples/appengine/example.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
window.fbAsyncInit = function() {
1818
FB.init({appId: '{{ facebook_app_id }}', status: true, cookie: true,
1919
xfbml: true});
20-
FB.Event.subscribe('auth.statusChange', function(response) {
20+
FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
2121
window.location.reload();
2222
});
2323
};
24-
2524
(function() {
2625
var e = document.createElement('script');
2726
e.type = 'text/javascript';

examples/appengine/example.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def current_user(self):
5757
# a round-trip to Facebook on every request
5858
user = User.get_by_key_name(cookie["uid"])
5959
if not user:
60-
graph = facebook.GraphAPI(cookie["oauth_access_token"])
60+
graph = facebook.GraphAPI(cookie["access_token"])
6161
profile = graph.get_object("me")
6262
user = User(key_name=str(profile["id"]),
6363
id=str(profile["id"]),
6464
name=profile["name"],
6565
profile_url=profile["profile_url"],
66-
access_token=cookie["oauth_access_token"])
66+
access_token=cookie["access_token"])
6767
user.put()
68-
elif user.access_token != cookie["oauth_access_token"]:
69-
user.access_token = cookie["oauth_access_token"]
68+
elif user.access_token != cookie["access_token"]:
69+
user.access_token = cookie["access_token"]
7070
user.put()
7171
self._current_user = user
7272
return self._current_user

examples/newsfeed/facebookclient.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ def current_user(self):
6060
# a round-trip to Facebook on every request
6161
user = User.get_by_key_name(cookie["uid"])
6262
if not user:
63-
graph = facebook.GraphAPI(cookie["oauth_access_token"])
63+
graph = facebook.GraphAPI(cookie["access_token"])
6464
profile = graph.get_object("me")
6565
user = User(key_name=str(profile["id"]),
6666
id=str(profile["id"]),
6767
name=profile["name"],
6868
profile_url=profile["profile_url"],
69-
access_token=cookie["oauth_access_token"])
69+
access_token=cookie["access_token"])
7070
user.put()
71-
elif user.access_token != cookie["oauth_access_token"]:
72-
user.access_token = cookie["oauth_access_token"]
71+
elif user.access_token != cookie["access_token"]:
72+
user.access_token = cookie["access_token"]
7373
user.put()
7474
self._current_user = user
7575
return self._current_user
@@ -97,10 +97,16 @@ def get(self):
9797
if not self.current_user:
9898
self.render("index.html")
9999
return
100-
news_feed = self.graph.get_connections("me", "home")
100+
try:
101+
news_feed = self.graph.get_connections("me", "home")
102+
except facebook.GraphAPIError:
103+
self.render("index.html")
104+
return
105+
except:
106+
news_feed = {"data": []}
101107
for post in news_feed["data"]:
102108
post["created_time"] = datetime.datetime.strptime(
103-
post["created_time"], "%Y-%m-%dT%H:%M:%S-0700") + \
109+
post["created_time"], "%Y-%m-%dT%H:%M:%S+0000") + \
104110
datetime.timedelta(hours=7)
105111
self.render("home.html", news_feed=news_feed)
106112

examples/newsfeed/templates/base.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
{% block head %}{% endblock %}
88
</head>
99
<body>
10-
<div id="promo">This application is a demo of the <a href="http://developers.facebook.com/docs/api">Facebook Graph API</a>, the core part of the <a href="http://developers.facebook.com/">Facebook Platform</a>. <a href="http://github.com/facebook/python-sdk/blob/master/examples/client/facebookclient.py">See source code &raquo;</a></div>
10+
<div id="promo">This application is a demo of the <a href="http://developers.facebook.com/docs/api">Facebook Graph API</a>, the core part of the <a href="http://developers.facebook.com/">Facebook Platform</a>. <a href="http://github.com/facebook/python-sdk/blob/master/examples/newsfeed/facebookclient.py">See source code &raquo;</a></div>
1111
<div id="body">{% block body %}{% endblock %}</div>
1212
<div id="fb-root"></div>
1313
<script>
1414
window.fbAsyncInit = function() {
1515
FB.init({appId: '{{ facebook_app_id }}', status: true, cookie: true, xfbml: true});
16-
FB.Event.subscribe('auth.statusChange', function(response) {
16+
FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
1717
window.location.reload();
1818
});
1919
};

examples/tornado/example.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
window.fbAsyncInit = function() {
1818
FB.init({appId: '{{ options.facebook_app_id }}', status: true,
1919
cookie: true, xfbml: true});
20-
FB.Event.subscribe('auth.statusChange', function(response) {
20+
FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
2121
window.location.reload();
2222
});
2323
};
24-
2524
(function() {
2625
var e = document.createElement('script');
2726
e.type = 'text/javascript';

examples/tornado/example.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ def get_current_user(self):
4848
user = self.db.get(
4949
"SELECT * FROM users WHERE id = %s", cookie["uid"])
5050
if not user:
51-
graph = facebook.GraphAPI(cookie["oauth_access_token"])
51+
# TODO: Make this fetch async rather than blocking
52+
graph = facebook.GraphAPI(cookie["access_token"])
5253
profile = graph.get_object("me")
5354
self.db.execute(
5455
"REPLACE INTO users (id, name, profile_url, access_token) "
5556
"VALUES (%s,%s,%s,%s)", profile["id"], profile["name"],
56-
profile["profile_url"], cookie["oauth_access_token"])
57+
profile["profile_url"], cookie["access_token"])
5758
user = self.db.get(
5859
"SELECT * FROM users WHERE id = %s", profile["id"])
59-
elif user.access_token != cookie["oauth_access_token"]:
60+
elif user.access_token != cookie["access_token"]:
6061
self.db.execute(
6162
"UPDATE users SET access_token = %s WHERE id = %s",
62-
cookie["oauth_access_token"], user.id)
63+
cookie["access_token"], user.id)
6364
return user
6465

6566
@property

src/facebook.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
2828
user = facebook.get_user_from_cookie(self.request.cookies, key, secret)
2929
if user:
30-
graph = facebook.GraphAPI(user["oauth_access_token"])
30+
graph = facebook.GraphAPI(user["access_token"])
3131
profile = graph.get_object("me")
3232
friends = graph.get_connections("me", "friends")
3333
@@ -193,7 +193,7 @@ def get_user_from_cookie(cookies, app_id, app_secret):
193193
cookie values.
194194
195195
If the user is logged in via Facebook, we return a dictionary with the
196-
keys "uid" and "oauth_access_token". The former is the user's Facebook ID,
196+
keys "uid" and "access_token". The former is the user's Facebook ID,
197197
and the latter can be used to make authenticated requests to the Graph API.
198198
If the user is not logged in, we return None.
199199

0 commit comments

Comments
 (0)