Commits

Anonymous committed ba8944a

Update to reflect new OAuth cookie name

  • Participants
  • Parent commits b2da20f

Comments (0)

Files changed (7)

File examples/appengine/example.html

       window.fbAsyncInit = function() {
         FB.init({appId: '{{ facebook_app_id }}', status: true, cookie: true,
                  xfbml: true});
-        FB.Event.subscribe('auth.statusChange', function(response) {
+        FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
           window.location.reload();
         });
       };
-
       (function() {
         var e = document.createElement('script');
         e.type = 'text/javascript';

File examples/appengine/example.py

                 # a round-trip to Facebook on every request
                 user = User.get_by_key_name(cookie["uid"])
                 if not user:
-                    graph = facebook.GraphAPI(cookie["oauth_access_token"])
+                    graph = facebook.GraphAPI(cookie["access_token"])
                     profile = graph.get_object("me")
                     user = User(key_name=str(profile["id"]),
                                 id=str(profile["id"]),
                                 name=profile["name"],
                                 profile_url=profile["profile_url"],
-                                access_token=cookie["oauth_access_token"])
+                                access_token=cookie["access_token"])
                     user.put()
-                elif user.access_token != cookie["oauth_access_token"]:
-                    user.access_token = cookie["oauth_access_token"]
+                elif user.access_token != cookie["access_token"]:
+                    user.access_token = cookie["access_token"]
                     user.put()
                 self._current_user = user
         return self._current_user

File examples/newsfeed/facebookclient.py

                 # a round-trip to Facebook on every request
                 user = User.get_by_key_name(cookie["uid"])
                 if not user:
-                    graph = facebook.GraphAPI(cookie["oauth_access_token"])
+                    graph = facebook.GraphAPI(cookie["access_token"])
                     profile = graph.get_object("me")
                     user = User(key_name=str(profile["id"]),
                                 id=str(profile["id"]),
                                 name=profile["name"],
                                 profile_url=profile["profile_url"],
-                                access_token=cookie["oauth_access_token"])
+                                access_token=cookie["access_token"])
                     user.put()
-                elif user.access_token != cookie["oauth_access_token"]:
-                    user.access_token = cookie["oauth_access_token"]
+                elif user.access_token != cookie["access_token"]:
+                    user.access_token = cookie["access_token"]
                     user.put()
                 self._current_user = user
         return self._current_user
         if not self.current_user:
             self.render("index.html")
             return
-        news_feed = self.graph.get_connections("me", "home")
+        try:
+            news_feed = self.graph.get_connections("me", "home")
+        except facebook.GraphAPIError:
+            self.render("index.html")
+            return
+        except:
+            news_feed = {"data": []}
         for post in news_feed["data"]:
             post["created_time"] = datetime.datetime.strptime(
-                post["created_time"], "%Y-%m-%dT%H:%M:%S-0700") + \
+                post["created_time"], "%Y-%m-%dT%H:%M:%S+0000") + \
                 datetime.timedelta(hours=7)
         self.render("home.html", news_feed=news_feed)
 

File examples/newsfeed/templates/base.html

     {% block head %}{% endblock %}
   </head>
   <body>
-    <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>
+    <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>
     <div id="body">{% block body %}{% endblock %}</div>
     <div id="fb-root"></div>
     <script>
       window.fbAsyncInit = function() {
         FB.init({appId: '{{ facebook_app_id }}', status: true, cookie: true, xfbml: true});
-        FB.Event.subscribe('auth.statusChange', function(response) {
+        FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
           window.location.reload();
         });
       };

File examples/tornado/example.html

       window.fbAsyncInit = function() {
         FB.init({appId: '{{ options.facebook_app_id }}', status: true,
                  cookie: true, xfbml: true});
-        FB.Event.subscribe('auth.statusChange', function(response) {
+        FB.Event.subscribe('{% if current_user %}auth.logout{% else %}auth.login{% endif %}', function(response) {
           window.location.reload();
         });
       };
-
       (function() {
         var e = document.createElement('script');
         e.type = 'text/javascript';

File examples/tornado/example.py

         user = self.db.get(
             "SELECT * FROM users WHERE id = %s", cookie["uid"])
         if not user:
-            graph = facebook.GraphAPI(cookie["oauth_access_token"])
+            # TODO: Make this fetch async rather than blocking
+            graph = facebook.GraphAPI(cookie["access_token"])
             profile = graph.get_object("me")
             self.db.execute(
                 "REPLACE INTO users (id, name, profile_url, access_token) "
                 "VALUES (%s,%s,%s,%s)", profile["id"], profile["name"],
-                profile["profile_url"], cookie["oauth_access_token"])
+                profile["profile_url"], cookie["access_token"])
             user = self.db.get(
                 "SELECT * FROM users WHERE id = %s", profile["id"])
-        elif user.access_token != cookie["oauth_access_token"]:
+        elif user.access_token != cookie["access_token"]:
             self.db.execute(
                 "UPDATE users SET access_token = %s WHERE id = %s",
-                cookie["oauth_access_token"], user.id)
+                cookie["access_token"], user.id)
         return user
 
     @property

File src/facebook.py

 
     user = facebook.get_user_from_cookie(self.request.cookies, key, secret)
     if user:
-        graph = facebook.GraphAPI(user["oauth_access_token"])
+        graph = facebook.GraphAPI(user["access_token"])
         profile = graph.get_object("me")
         friends = graph.get_connections("me", "friends")
 
     cookie values.
 
     If the user is logged in via Facebook, we return a dictionary with the
-    keys "uid" and "oauth_access_token". The former is the user's Facebook ID,
+    keys "uid" and "access_token". The former is the user's Facebook ID,
     and the latter can be used to make authenticated requests to the Graph API.
     If the user is not logged in, we return None.