本文整理匯總了Python中pyfb.Pyfb.get_auth_code_url方法的典型用法代碼示例。如果您正苦於以下問題:Python Pyfb.get_auth_code_url方法的具體用法?Python Pyfb.get_auth_code_url怎麽用?Python Pyfb.get_auth_code_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyfb.Pyfb
的用法示例。
在下文中一共展示了Pyfb.get_auth_code_url方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: facebook_login
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
def facebook_login(request):
# Gets the auth redirect url with code provided from facebook.
facebook = Pyfb(
settings.CLIENT_ID,
permissions=settings.FACEBOOK_SCOPE
)
auth_code_url = facebook.get_auth_code_url(
redirect_uri=settings.REDIRECT_URL
)
return HttpResponseRedirect(auth_code_url)
示例2: facebook_login
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
def facebook_login(request):
facebook = Pyfb(settings.CLIENT_ID, permissions=[
'publish_actions',
'publish_pages',
'user_photos',
'user_posts',
'manage_pages',
'user_about_me',
'email'
])
auth_code_url = facebook.get_auth_code_url(redirect_uri=settings.REDIRECT_URL)
return HttpResponseRedirect(auth_code_url)
示例3: FacebookLogin
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
def FacebookLogin (request):
facebook = Pyfb(FACEBOOK_APP_ID)
return HttpResponseRedirect(facebook.get_auth_code_url(redirect_uri=FACEBOOK_REDIRECT_URL))
示例4: facebook_login
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
def facebook_login(request):
facebook = Pyfb(settings.FACEBOOK_APP_ID)
return HttpResponseRedirect(facebook.get_auth_code_url(redirect_uri=settings.FACEBOOK_REDIRECT_URL))
示例5: facebook_login
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
def facebook_login(request):
if "access_token" not in request.session:
facebook = Pyfb(FACEBOOK_APP_ID)
return HttpResponseRedirect(facebook.get_auth_code_url(redirect_uri=FACEBOOK_REDIRECT_URL))
return redirect('/account/dashboard')
示例6: __init__
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import get_auth_code_url [as 別名]
class FacebookAccount:
"""Wrapper for facebook API """
def __init__(self):
self.user = None
self._user_id = None
self._access_token = None
self._api = Pyfb(FACEBOOK_APP_ID)
self._auth_code = None
def is_authorized(self):
"""Check if alreade authorized via FB"""
if self._access_token is None:
return False
return True
def _load_user_info(self):
"""Get out user info"""
fb_user = self._api.get_myself()
if fb_user is None:
return False
self.user = fb_user.name
self._user_id = str(fb_user.id)
return True
def get_auth_url(self):
"""Return URL for authorization"""
url = self._api.get_auth_code_url(redirect_uri=FACEBOOK_REDIRECT_URL)
return url
def set_auth_code(self, code):
"""Save auth. code returned from FB in case of sucessfull login"""
self._auth_code = code
def request_access_token(self):
"""Request access token from FB"""
self._access_token = self._api.get_access_token(
FACEBOOK_APP_SECRET, self._auth_code, redirect_uri=FACEBOOK_REDIRECT_URL
)
print "FB access token: %s" % self._access_token
# def get_extended_at(self, short_lived_access_token):
# """Get long time lived access token from short lived."""
# from facepy.utils import get_extended_access_token
# long_lived_access_token, expires_at = get_extended_access_token(
# short_lived_access_token,
# FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
# return long_lived_access_token
def load_messages(self, messages):
"""Load Messages from Twitter"""
if not self.is_authorized():
return False
if self.user is None:
if not self._load_user_info():
return False
print "facebook_access_token=%s" % self._access_token
url = "https://graph.facebook.com/%s/posts?access_token=%s" % (self._user_id, self._access_token)
req = urllib2.Request(url)
try:
response = urllib2.urlopen(req)
except ValueError:
print "Connection Error - Cannot load data from Facebook "
return False
# load data to json
page = response.read()
fb_data = json.loads(page)
# print json.dumps(fb_data,indent=2)
response.close()
# Parse loaded data
msg_count = 0
for msg in fb_data["data"]:
text = ""
# if 'story' field found use it as a main text to be shown
if "story" in msg:
text = msg["story"]
# Use text from 'message field as a text instead of 'story'
# if 'message' field exist
if "message" in msg: #
text = msg["message"]
# create a new message key from timestamp + 'f'
# where 'f' is added to be unique ('f' means - facebook)
record_key = str(to_timestamp(msg["created_time"])) + "f"
# fill out message with data
record = {"account": "facebook", "created": to_ctime(msg["created_time"]), "text": text}
if text.find(" likes") >= 0:
# Additionally parse url if this is 'like'-message
picture_id = msg["id"][msg["id"].find("_") + 1 :]
record["description"] = FB_POST_URL % (self._user_id, picture_id)
record["link"] = FB_POST_URL % (self._user_id, picture_id)
if "link" in msg:
record["link"] = msg["link"]
#.........這裏部分代碼省略.........