本文整理汇总了Python中facebook.Facebook.get_login_url方法的典型用法代码示例。如果您正苦于以下问题:Python Facebook.get_login_url方法的具体用法?Python Facebook.get_login_url怎么用?Python Facebook.get_login_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebook.Facebook
的用法示例。
在下文中一共展示了Facebook.get_login_url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_facebook
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_login_url [as 别名]
def setup_facebook():
FB_SETTINGS = '.facebook'
from facebook import Facebook
# Get api_key and secret_key from a file
fbs = open(FB_SETTINGS).readlines()
facebook = Facebook(fbs[0].strip(), fbs[1].strip())
facebook.auth.createToken()
print facebook.get_login_url()
#facebook.session_key = "1b2fcc7cabfc2574898155c2-1926269"
#facebook.secret = u'd21ee6b6b24515fb00af58fa3bfea907'
raw_input("waiting")
facebook.auth.getSession()
return facebook
示例2: web_app
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_login_url [as 别名]
def web_app(request):
"""Get the user's friends and their pictures. This example uses
the Django web framework, but should be adaptable to others."""
# Get api_key and secret_key from a file
fb_file = open('facebook_keys.txt').readlines()
api_key = fb_file[0].strip()
secret_key = fb_file[1].strip()
fb = Facebook(api_key, secret_key)
# Use the data from the cookie if present
if 'session_key' in request.session and 'uid' in request.session:
fb.session_key = request.session['session_key']
fb.uid = request.session['uid']
else:
try:
fb.auth_token = request.GET['auth_token']
except KeyError:
# Send user to the Facebook to login
return HttpResponseRedirect(fb.get_login_url())
# getSession sets the session_key and uid
# Store these in the cookie so we don't have to get them again
fb.auth.getSession()
request.session['session_key'] = fb.session_key
request.session['uid'] = fb.uid
try:
friend_ids = fb.friends.get()
except FacebookError, e:
# Error 102 means the session has expired.
# Delete the cookie and send the user to Facebook to login
if e.info['code'] == u'102':
del request.session['session_key']
del request.session['uid']
return HttpResponseRedirect(fb.get_login_url())
else:
# Other Facebook errors are possible too. Don't ignore them.
raise
示例3: FacebookRequestHandler
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_login_url [as 别名]
class FacebookRequestHandler(RequestHandler):
"""
Base class for request handlers for Facebook apps, providing useful
Facebook-related tools: a local
"""
def _fbconfig_value(self, name, default=None):
"""
Checks the global config dictionary and then for a class/instance
variable, using a provided default if no value is found.
"""
if name in FACEBOOK_CONFIG:
default = FACEBOOK_CONFIG[name]
return getattr(self, name, default)
def initialize(self, request, response):
"""
Initialize's this request's Facebook client.
"""
super(FacebookRequestHandler, self).initialize(request, response)
app_name = self._fbconfig_value("app_name", "")
api_key = self._fbconfig_value("api_key", None)
secret_key = self._fbconfig_value("secret_key", None)
self.facebook = Facebook(api_key, secret_key, app_name=app_name)
require_app = self._fbconfig_value("require_app", False)
require_login = self._fbconfig_value("require_login", False)
need_session = self._fbconfig_value("need_session", False)
check_session = self._fbconfig_value("check_session", True)
self._messages = None
self.redirecting = False
if require_app or require_login:
if not self.facebook.check_session(request):
self.redirect(self.facebook.get_login_url(next=request.url))
self.redirecting = True
return
elif check_session:
self.facebook.check_session(request) # ignore response
# NOTE: require_app is deprecated according to modern Facebook login
# policies. Included for completeness, but unnecessary.
if require_app and not self.facebook.added:
self.redirect(self.facebook.get_add_url(next=request.url))
self.redirecting = True
return
if not (require_app or require_login) and need_session:
self.facebook.auth.getSession()
def redirect(self, url, **kwargs):
"""
For Facebook canvas pages we should use <fb:redirect /> instead of
a normal redirect.
"""
if self.facebook.in_canvas:
self.response.clear()
self.response.out.write('<fb:redirect url="%s" />' % (url,))
else:
super(FacebookRequestHandler, self).redirect(url, **kwargs)
def add_user_message(self, kind, msg, detail="", time=15 * 60):
"""
Add a message to the current user to memcache.
"""
if self.facebook.uid:
key = "messages:%s" % self.facebook.uid
self._messages = memcache.get(key)
message = {"kind": kind, "message": msg, "detail": detail}
if self._messages is not None:
self._messages.append(message)
else:
self._messages = [message]
memcache.set(key, self._messages, time=time)
def get_and_delete_user_messages(self):
"""
Get all of the messages for the current user; removing them.
"""
if self.facebook.uid:
key = "messages:%s" % self.facebook.uid
if not hasattr(self, "_messages") or self._messages is None:
self._messages = memcache.get(key)
memcache.delete(key)
return self._messages
return None
示例4: MainWindow
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_login_url [as 别名]
class MainWindow(QtGui.QDialog):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.selectFileButton = QPushButton('Select File',self)
self.connect(self.selectFileButton,SIGNAL("clicked()"), self._selectFile)
self.loginButton = QPushButton('Login',self)
self.connect(self.loginButton,SIGNAL("clicked()"), self._login)
mainLayout = QtGui.QGridLayout()
mainLayout.addWidget(self.selectFileButton,0,0)
mainLayout.addWidget(self.loginButton,0,1)
self.setLayout(mainLayout)
self.stage = 0
self.options = {0:self._loginStage1,
1:self._loginStage2,
2:self._loginStage3,
3:self._loginEnd}
cf = ConfigFile(config_file_path)
# get api_key, secret_key and app_Id
try:
self.api_key = cf.api_key
self.secret_key = cf.secret_key
self.app_Id = cf.app_Id
except:
self.api_key = ''
self.secret_key = ''
self.app_Id = ''
# get token and expire time
try:
self.token = cf.token
self.expire = val(cf.expire)
except:
self.token = 0
self.expire = 0
self.facebook = Facebook(self.api_key, self.secret_key)
self.facebook.auth.createToken()
def _selectFile(self):
self.excelFileName = QFileDialog.getOpenFileName(self,"FileDialog","", "*.xls", "*.xls")
reader = ExcelFileReader()
reader.load(self.excelFileName)
print reader.getHeader()
print len(reader)
for r in reader:
print r
def _login(self):
auth_url = self.facebook.get_login_url(next=None,popup=True,canvas=True)
self.loginWindow = LoginWindow(self)
self.loginWindow.view.loadFinished.connect(self._stateMachine)
self.loginWindow.show()
self.loginWindow.view.load(QUrl(auth_url))
self.loginButton.hide()
def _stateMachine(self):
self.options[self.stage]()
def _loginStage1(self):
url = str(self.loginWindow.view.url().toString())
parser = ParseFacebookUrl(url)
if parser.url != 'https://ssl.facebook.com/desktopapp.php':
return
if parser.query.has_key('api_key')==True:
if parser.query['api_key'] == self.api_key:
if skip_auth == False:
self.stage = 1
extpermurl = self.facebook.get_ext_perm_url(ext_perm='publish_stream', next=None, popup=True)
self.loginWindow.view.load(QUrl(extpermurl))
else:
self.stage = 2
self._stateMachine()
def _loginStage2(self):
self.stage = 2
def _loginStage3(self):
self.stage = 3
self.facebook.auth.getSession()
# photos = self.facebook.photos.createAlbum('test album2','home','interesting test album')
# print photos
# self.facebook.photos.upload(image='C:\\Temp\\facebookupload\\uploadphoto\\logo.gif', aid=photos[u'aid'], caption='good')
def _loginEnd(self):
self.stage = 4