本文整理汇总了Python中facebook.Facebook.uid方法的典型用法代码示例。如果您正苦于以下问题:Python Facebook.uid方法的具体用法?Python Facebook.uid怎么用?Python Facebook.uid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebook.Facebook
的用法示例。
在下文中一共展示了Facebook.uid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: facebook
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import uid [as 别名]
def facebook(self):
"""Get a facebook object, if pyfacebook is present, the user is logged
in and is a facebook connect user. Otherwise this is None."""
try:
from facebook import Facebook
except ImportError:
log.warning("PyFacebook is not installed!")
else:
if self.user and self.user.profile.uses_facebook_connect:
# This implies, that the correct cookies must be set. We don't
# double check for that.
api_key = get_app().cfg['facebook/api_key']
secret_key = get_app().cfg['facebook/secret_key']
facebook = Facebook(api_key, secret_key)
# Setting the cookie values
# It's so cool to have no private attributes. (;
facebook.uid = self.session['fb_user_id']
facebook.session_key = self.session['fb_session_id']
return facebook
示例2: web_app
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import uid [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: get_facebook_viewer_info
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import uid [as 别名]
def get_facebook_viewer_info(self, user_id):
fb = Facebook(facebook_api_key, facebook_secret)
viewer_info = {}
fb.uid = user_id
viewer_info['container_user_id'] = fb.uid
viewer_info['domain'] = 'facebook.com'
try:
info = fb.users.getInfo([fb.uid], ['name', 'pic', 'profile_url'])
if len(info) > 0:
viewer_info['display_name'] = info[0]['name']
viewer_info['display_name'] = re.sub(r'[\'\"<>`]', ' ', viewer_info['display_name'])
viewer_info['profile_url'] = info[0]['profile_url']
viewer_info['profile_image_url'] = info[0]['pic']
return viewer_info
except FacebookError, e:
logging.info('exception getting facebook user info: %s' % e)
# Error 102 means the session has expired.
logging.info(e.code)
if e.code == u'102':
logging.info('equals u102')
return viewer_info
logging.info('not equal to u102 [%s]' % e.code)
示例4: open
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import uid [as 别名]
file_uid_write = open(unicode(home)+unicode("faccialibro.user-id"),"w+")
file_uid_write.write(str(session['uid']))
file_uid_write.close()
file_secret_write = open(unicode(home)+unicode("faccialibro.secret"),"w+")
file_secret_write.write(str(session['secret']))
file_secret_write.close()
else:
file_uid = open(unicode(home)+unicode("faccialibro.user-id"),"r")
uid_read = file_uid.read()
file_uid.close()
file_secret = open(unicode(home)+unicode("faccialibro.secret"),"r")
secret_read = file_secret.read()
file_secret.close()
fb = Facebook(api_key='261918900490462', secret_key='c2bb3994ddcd0078e33bc9fb63daa434')
fb.session_key = session_read
fb.uid = uid_read
fb.secret = secret_read
loop = GObject.MainLoop()
launcher = Unity.LauncherEntry.get_for_desktop_id ("Faccialibro.desktop")
current_unseen = 0
unseen_changed = False
def updates():
global current_unseen, unseen_changed
notifiche = fb.notifications.get()
unseen = notifiche['notification_counts']['unseen'] + notifiche['messages']['unseen'] + notifiche['friend_requests_counts']['unseen']
if unseen == current_unseen:
unseen_changed = False
elif unseen > 0:
launcher.set_property("count", unseen)
launcher.set_property("count_visible", True)
if unseen > current_unseen:
示例5: open
# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import uid [as 别名]
from xml.dom.minidom import parse
from time import sleep,localtime,strftime
# Get api_key and secret_key from a file
fbs = open('facebook_keys.txt').readlines()
facebook = Facebook(fbs[0].strip(), fbs[1].strip())
while True:
print strftime("%a, %d %b %Y %H:%M:%S", localtime())
try:
session = load(file(".session"))
print session
facebook.secret = session['secret']
facebook.session_key = session['session_key']
facebook.session_key_expires = session['expires']
facebook.uid = session['uid']
except (EOFError,IOError):
token = facebook.auth.createToken()
print "token",facebook.auth._client.auth_token
# Show login window
facebook.login()
# Login to the window, then press enter
print 'After logging in, press enter...'
raw_input()
res = facebook.auth.getSession()
dump(res,file(".session","w"))
try:
data = parse(urlopen("http://twitter.com/statuses/user_timeline/palfrey.xml"))