当前位置: 首页>>代码示例>>Python>>正文


Python Facebook.session_key方法代码示例

本文整理汇总了Python中facebook.Facebook.session_key方法的典型用法代码示例。如果您正苦于以下问题:Python Facebook.session_key方法的具体用法?Python Facebook.session_key怎么用?Python Facebook.session_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在facebook.Facebook的用法示例。


在下文中一共展示了Facebook.session_key方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
 def process(self, file):
     facebook = Facebook(self.apikey, self.secret)
     facebook.session_key = file["fbsession"]
     try:
         userinfo = facebook.users.getLoggedInUser()
     except FacebookError, e:
         # TODO: Error handling. What do we do if the user isn't logged in?
         if e.code == 102:  # session key has expired
             log.info("%s is not a valid session, removing upload", file["fbsession"])
             file["msg"] = "Facebook session not valid"
             file["na"] = na.AUTHENTICATE
             self.cleanup(file)
             return False
开发者ID:JustinTulloss,项目名称:harmonize.fm,代码行数:15,代码来源:facebookaction.py

示例2: get_connected_friends

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
def get_connected_friends(api_key, secret_key, fb_session_key, fb_uid, retry=0):
    """Return a list with the FB user's friends' IDs that are connected to our app"""
    retval = []
    try:
        facebook = Facebook(api_key, secret_key)
        facebook.session_key = fb_session_key
        info = facebook.friends.getAppUsers()
        retval = info
    except urllib2.URLError, ue:
        if retry < _MAX_RETRIES:
            # retry once
            time.sleep(0.1)
            return get_connected_friends(api_key, secret_key, fb_session_key, fb_uid, retry=retry + 1)
        else:
            _log.exception(ue)
            _log.warn("Could not get FB friends: %s", fb_uid)
开发者ID:kabirh,项目名称:riotvine,代码行数:18,代码来源:utils.py

示例3: get_user_info

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
def get_user_info(api_key, secret_key, fb_session_key, fb_uid, retry=0):
    """Return a dictionary with the FB user's name and email address"""
    retval = {"name": None, "email": None}
    try:
        facebook = Facebook(api_key, secret_key)
        facebook.session_key = fb_session_key
        info = facebook.users.getInfo([fb_uid], ["name", "proxied_email"])[0]
        retval["name"] = info.get("name", None)
        retval["email"] = info.get("proxied_email", None)
    except urllib2.URLError, ue:
        if retry < _MAX_RETRIES:
            # retry once
            time.sleep(0.1)
            return get_user_info(api_key, secret_key, fb_session_key, fb_uid, retry=retry + 1)
        else:
            _log.exception(ue)
            _log.warn("Could not get FB user info: %s", fb_uid)
开发者ID:kabirh,项目名称:riotvine,代码行数:19,代码来源:utils.py

示例4: facebook

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [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
开发者ID:passy,项目名称:rdreilib,代码行数:21,代码来源:wrappers.py

示例5: web_app

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [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
开发者ID:RockHoward,项目名称:pyfacebook,代码行数:42,代码来源:examples.py

示例6: open

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
    file_session_write.close()
    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)
开发者ID:Bloodominick,项目名称:Faccialibro,代码行数:33,代码来源:faccialibro.py

示例7: Facebook

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
#sudo apt-get install python-facebook
#source http://stackoverflow.com/a/5191033
from facebook import Facebook
#creat app via visiting https://developers.facebook.com/apps and get below keys
api_key = '273762xxxxxxxx'
secret  = 'dffc85xxxxxxxxxxxxxxxxx'

session_key = '451XXX'
#session_onetime_code = 'LX2XXX'

ga = Facebook(api_key, secret)
ga.session_key = session_key

# now use the ga object for playing around
#You might need to get an infinite session key which you can get from here: http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

#Use this code to get convert the code from above URL into infinite session key:

def generate_session_from_onetime_code(ga, code):
    ga.auth_token = code
    return ga.auth.getSession()
print generate_session_from_onetime_code(ga, session_key)

print ga


#sourch http://blog.chmouel.com/2010/01/09/get-facebook-albums-with-python/
import os
import urllib
#ga.auth.createToken()
#ga.login()
开发者ID:animesh,项目名称:scripts,代码行数:33,代码来源:fbgetalbum.py

示例8: open

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import session_key [as 别名]
from pickle import dump,load
from urllib2 import *
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:
开发者ID:palfrey,项目名称:dotfiles,代码行数:33,代码来源:twitter_facebook.py


注:本文中的facebook.Facebook.session_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。