本文整理汇总了Python中open_facebook.api.OpenFacebook._me方法的典型用法代码示例。如果您正苦于以下问题:Python OpenFacebook._me方法的具体用法?Python OpenFacebook._me怎么用?Python OpenFacebook._me使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类open_facebook.api.OpenFacebook
的用法示例。
在下文中一共展示了OpenFacebook._me方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_persistent_graph
# 需要导入模块: from open_facebook.api import OpenFacebook [as 别名]
# 或者: from open_facebook.api.OpenFacebook import _me [as 别名]
def get_persistent_graph(request, *args, **kwargs):
'''
Wraps itself around get facebook graph
But stores the graph in the session, allowing usage across multiple
pageviews.
Note that Facebook session's expire at some point, you can't store this
for permanent usage
Atleast not without asking for the offline_access permission
'''
from open_facebook.api import OpenFacebook
if not request:
logger.info("GPG01 no request")
raise(ValidationError,
'Request is required if you want to use persistent tokens')
graph = None
# some situations like an expired access token require us to refresh our
# graph
require_refresh = False
code = request.REQUEST.get('code')
logger.info("GPG02 code = %s" % code)
if code:
require_refresh = True
local_graph = getattr(request, 'facebook', None)
logger.info("GPG03 local_graph %s" % local_graph)
if local_graph:
# gets the graph from the local memory if available
graph = local_graph
if not graph:
logger.info("GPG04 no graph")
# search for the graph in the session
cached_graph_dict = request.session.get('graph_dict')
if cached_graph_dict:
logger.info("GPG05 graph in session")
graph = OpenFacebook()
graph.__setstate__(cached_graph_dict)
graph._me = None
if not graph or require_refresh:
# gets the new graph, note this might do token conversions (slow)
logger.info("GPG06 getting graph")
graph = get_facebook_graph(request, *args, **kwargs)
# if it's valid replace the old cache
if graph is not None and graph.access_token:
logger.info("GPG07 put graph into session")
request.session['graph_dict'] = graph.__getstate__()
# add the current user id and cache the graph at the request level
_add_current_user_id(graph, request.user)
request.facebook = graph
return graph