Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Minor changes to FacebookAuthBrowser #1

Merged
merged 1 commit into from almost 2 years ago

2 participants

neonknight Víctor R. Ruiz
neonknight

Hi, I added a few minor changes to make it even easier to use your awesome class in a project:

  • removed print statement (replaced by stderr out, can be disabled)
  • close browser window after login (can be disabled)
  • make token file configurable
Víctor R. Ruiz
Owner

Looks good! Thanks for the contribution.

Víctor R. Ruiz vrruiz merged commit 06be9f5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 2 authors.

Sep 10, 2012
Neonknight removed print statement, close browser window after login, make token…
… file configurable
236a8c8
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 17 additions and 5 deletions. Show diff stats Hide diff stats

  1. +17 5 FacebookAuth.py
22 FacebookAuth.py
@@ -4,23 +4,27 @@
4 4 import webkit
5 5 import urllib
6 6 import urlparse
  7 +import sys
7 8
8 9 FB_TOKEN_FILE = 'access_token.txt'
9 10
10   -class Browser:
  11 +class Browser(object):
11 12 """ Creates a web browser using GTK+ and WebKit to authorize a
12 13 desktop application in Facebook. It uses OAuth 2.0.
13 14 Requires the Facebook's Application ID. The token is then
14 15 saved to FB_TOKEN_FILE.
15 16 """
16 17
17   - def __init__(self, app_key, scope='offline_access'):
  18 + def __init__(self, app_key, scope='offline_access', token_file=FB_TOKEN_FILE):
18 19 """ Constructor. Creates the GTK+ app and adds the WebKit widget
19 20 @param app_key Application key ID (Public).
20 21
21 22 @param scope A string list of permissions to ask for. More at
22 23 http://developers.facebook.com/docs/reference/api/permissions/
23 24 """
  25 + self.debug = False
  26 + self.close_window = True
  27 + self.token_file = token_file
24 28 self.token = ''
25 29 self.token_expire = ''
26 30 self.scope = scope
@@ -60,11 +64,19 @@ def _load_committed_cb(self, web_view, frame):
60 64 self.token = params['access_token'][0]
61 65 self.token_expire = params['expires_in'][0] # Should be equal to 0, don't expire
62 66 # Save token to file
63   - token_file = open(FB_TOKEN_FILE, 'w')
  67 + token_file = open(self.token_file, 'w')
64 68 token_file.write(self.token)
65 69 token_file.close()
66   - print "Authentication done. Access token available at %s" % (FB_TOKEN_FILE)
  70 + if self.debug:
  71 + sys.stderr.write("Authentication done. Access token available at %s\n" % (self.token_file))
67 72 gtk.main_quit() # Finish
  73 + if self.close_window:
  74 + try:
  75 + self.window.destroy()
  76 + except RuntimeError:
  77 + pass
  78 +
  79 +
68 80
69 81 def _destroy_event_cb(self, widget):
70 82 """ Callback for close window. Closes the application. """
@@ -77,7 +89,7 @@ def authorize(self):
77 89
78 90 if (__name__ == '__main__'):
79 91 # Creates the browser
80   - browser = Browser(app_key='XXXXXXXXXXX', scope='offline_access,read_stream')
  92 + browser = Browser(app_key='XXXXXXXXXXX', scope='offline_access,read_stream', token_file=FB_TOKEN_FILE)
81 93 # Launch browser window
82 94 browser.authorize()
83 95 # Token available?

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.