本文整理匯總了Python中pyfb.Pyfb.set_access_token方法的典型用法代碼示例。如果您正苦於以下問題:Python Pyfb.set_access_token方法的具體用法?Python Pyfb.set_access_token怎麽用?Python Pyfb.set_access_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyfb.Pyfb
的用法示例。
在下文中一共展示了Pyfb.set_access_token方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PyfbTests
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
class PyfbTests(unittest.TestCase):
pyfb_args = {}
def setUp(self):
self.pyfb = Pyfb(config["FACEBOOK_APP_ID"], **self.pyfb_args)
self.pyfb.set_access_token(config["FACEBOOK_TOKEN"])
self.me = self.pyfb.get_myself()
def test_auth(self):
self.assertEquals(type(self.me.name), type(unicode()))
def test_get_friends(self):
self.assertTrue(isinstance(self.pyfb.get_friends(self.me.id), list))
def test_get_photos_paging(self):
photos = self.pyfb.get_photos()
more_photos = photos.next()
more_more_photos = more_photos.next()
if len(photos) < 25 and len(more_photos) > 0:
raise Exception()
if len(photos) == 25 and len(more_photos) < 25 and len(more_more_photos) > 0:
raise Exception()
self.assertTrue(isinstance(photos, list))
self.assertTrue(isinstance(more_photos, list))
self.assertTrue(isinstance(more_more_photos, list))
self.assertEquals(len(photos), len(more_photos.previous()))
self.assertEquals(photos.previous(), [])
示例2: facebook_javascript_login_sucess
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def facebook_javascript_login_sucess(request):
access_token = request.GET.get("access_token")
facebook = Pyfb(FACEBOOK_APP_ID)
facebook.set_access_token(access_token)
return _render_user(facebook)
示例3: facebook_login_success
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def facebook_login_success(request):
code = request.GET.get('code')
facebook = Pyfb(FACEBOOK_APP_ID)
access_token = facebook.get_access_token(FACEBOOK_SECRET_KEY, code, redirect_uri=FACEBOOK_REDIRECT_URL)
facebook.set_access_token(access_token)
request.session['access_token'] = access_token
return render_user(facebook, request)
示例4: setpassword
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def setpassword(request, idnum):
idnum = int(idnum)
try:
fb = FacebookProfiles.objects.get(fbk_id = idnum)
facebook = Pyfb(settings.FACEBOOK_APP_ID)
facebook.set_access_token(fb.fbk_token)
me = facebook.get_user_by_id(id = fb.fbk_id)
user = fb.user
except ObjectDoesNotExist:
return HttpResponseRedirect('/')
if request.method == 'POST':
form = PasswordSetForm(request.POST)
if form.is_valid():
user.set_password(form.cleaned_data['password'])
user.save()
authuser = authenticate(username=user.username, password=form.cleaned_data['password'])
if authuser is not None:
login(request, authuser)
return HttpResponseRedirect('/auth/welcome/')
else:
form = PasswordSetForm()
var = RequestContext(request, {
'form':form,
'me':me,
'user':user
})
return render_to_response('registration/facebook.html', var)
示例5: get
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def get(self, user_token):
#return {User_data: User[token]}
FACEBOOK_APP_ID = '134416106741047'
facebook = Pyfb(FACEBOOK_APP_ID)
#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
facebook.authenticate()
#Copy the [access_token] and enter it below
getToken = user_token#'CAACEdEose0cBACIgotCQGDecYsWW1O7wrc5saw0ZCxrM8nKzF3wWgIvQqGyb9H5u3MIBKak9jcYc3l1CNZCdYniVI3tweTC8vX2PdibMlJrdrH1LIeJnmgWQS8WpkXyRzY8dpvGgFDZARq2amdAZBEXEXJePKSuMqTIOXCCfQMzNd3QMtldxD25lkFg3IANRVfjviSo6uQZDZD'
#Sets the authentication token
facebook.set_access_token(getToken)
#Gets info about myself
me = facebook.get_myself()
me_pic = facebook.fql_query('SELECT pic_small FROM user WHERE uid = me()')
#friends = facebook.get_friends()
me_name = me.name
me_id = me.id
me_gender = me.gender
location = getattr(me, "location")
me_location = location.name
for i in me_pic:
try:
my_pic = i.pic_small
except AttributeError:
my_pic = 'None'
try:
me_birthday = me.birthday
except AttributeError:
me_birthday = 'None'
try:
me_status = me.relationship_status
except AttributeError:
me_status = 'None'
try:
me_link = me.link
except AttributeError:
me_link = 'None'
me_all = {'name': me_name, 'id': me_id, 'gender': me_gender, 'location': me_location, 'birthday': me_birthday, 'status': me_status, 'link': me_link, 'picture': my_pic }
#db.dannysaban.insert(me_all)
#print 'me - done!'
#get_me = db.dannysaban.find({'id': me_id})
return me_all
''' update user data '''
示例6: pyfbTests
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
class pyfbTests(unittest.TestCase):
def setUp(self):
self.facebook = Pyfb(FACEBOOK_APP_ID)
self.facebook.set_access_token(FACEBOOK_TOKEN)
self.me = self.facebook.get_myself()
def test_auth(self):
self.assertEquals(type(self.me.name), type(unicode()))
def test_get_friends(self):
self.assertEquals(type(self.facebook.get_friends(self.me.id)), type(list()))
示例7: login_facebook
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def login_facebook(request):
if 'access_token' not in request.GET:
return Response(ReturnObject(RetCode._FAIL, _('Access token not exist in request'), None).to_json())
try:
access_token = request.GET.get('access_token')
facebook = Pyfb(FACEBOOK_APP_ID)
facebook.set_access_token(access_token)
result = _render_user(facebook, request)
if result != '':
return Response(ReturnObject(RetCode._FAIL, result, None).to_json())
else:
current_player = get_current_user(request)
return Response(ReturnObject(RetCode._SUCCESS, _('Login successfully'), current_player).to_json())
except Exception, error:
return Response(ReturnObject(RetCode._SYSTEM_ERROR, _('System error, access token is wrong'), None).to_json())
示例8: feed
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def feed(request):
usergenres = request.user.genretouser.all()
user = request.user
if request.method == 'POST':
form = PostingForm(request.POST)
if form.is_valid():
if request.POST.get('facebookshare'):
try:
fb = FacebookProfiles.objects.get(user=user)
fbk = Pyfb(settings.FACEBOOK_APP_ID, settings.FACEBOOK_SECRET_KEY)
fbk.set_access_token(fb.fbk_token)
fbk.publish(message=form.cleaned_data['content'], id=fb.fbk_id)
except ObjectDoesNotExist:
pass
if request.POST.get('twittershare'):
try:
tw = TwitterProfiles.objects.get(user=user)
twttr = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
twttr.set_access_token(tw.oauth_token, tw.oauth_secret)
api = tweepy.API(twttr)
me = api.me()
api.update_status(form.cleaned_data['content'] + ' via @likewyss')
except ObjectDoesNotExist:
pass
return HttpResponseRedirect('/feed/')
else:
form = PostingForm()
var = RequestContext(request, {
'form':form,
'user':request.user,
'genres':usergenres
})
return render_to_response('pages/feed.html', var)
示例9: Pyfb
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
#Your APP ID. It Needs to register your application on facebook
#http://developers.facebook.com/
FACEBOOK_APP_ID = '178358228892649'
facebook = Pyfb(FACEBOOK_APP_ID)
#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
facebook.authenticate()
#Copy the [access_token] and enter it below
token = raw_input("Enter the access_token\n")
#Sets the authentication token
facebook.set_access_token(token)
#Gets info about myself
me = facebook.get_myself()
print "-" * 40
print "Name: %s" % me.name
print "From: %s" % me.hometown.name
print
print "Speaks:"
for language in me.languages:
print "- %s" % language.name
print
print "Worked at:"
示例10: FacebookMobileLogin
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
def FacebookMobileLogin (request):
if request.method == 'POST':
primary_user = 1
facebook_id = request.POST.get('fb_user_id', None)
facebook_email = request.POST.get('fb_user_email', None)
token = request.POST.get('oauth_token', None)
expiration = request.POST.get('expiration', None)
creation = request.POST.get('created', None)
if not request.user.is_authenticated():
if token and expiration and creation:
new_token = OAuthToken(token=token, issued_at=datetime.fromtimestamp(float(creation)),
expires_at=datetime.fromtimestamp(float(expiration)))
new_token.save()
facebook = Pyfb(FACEBOOK_APP_ID)
facebook.set_access_token(token)
me = facebook.get_myself()
if (type(me.name) == type(unicode())):
try:
find_fb_user = FacebookAppUser.objects.get(fb_uid=me.id)
find_fb_user.oauth_token = new_token
find_fb_user.save()
user = User.objects.get(pk=find_fb_user.appuser.user.pk)
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
#response = json.dumps({'status': 'success', 'user':user})
serialized_response = serializers.serialize('json', [find_fb_user.appuser, ], relations={
'user': {'fields': ( 'username', 'first_name', 'last_name', 'email', )},
'facebook_user': {'fields': ( 'fb_uid', 'fb_email', )}, })
return HttpResponse(serialized_response, mimetype="application/json")
except FacebookAppUser.DoesNotExist:
birthday = None
if hasattr(me, 'birthday'):
birthday = datetime.strptime(me.birthday, '%m/%d/%Y')
new_fb_user = FacebookAppUser(user_id=primary_user, fb_uid=me.id, fb_email=me.email,
oauth_token=new_token)
new_fb_user.save()
new_user = User.objects.create_user(username=me.username.lower(), email=me.email,
password=token)
new_user.first_name = me.first_name
new_user.last_name = me.last_name
new_user.save()
new_appuser = AppUser(user=new_user, facebook_user=new_fb_user, gender=me.gender,
birthdate=birthday)
new_appuser.save()
new_fb_user.appuser = new_appuser
new_fb_user.save()
new_user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, new_user)
#response = json.dumps({'status': 'success', 'user':new_user})
#serialized_response = serializers.serialize('json', [ new_user, ])
#return HttpResponse(me.__dict__)
serialized_response = serializers.serialize('json', [new_appuser, ], relations={
'user': {'fields': ('username', 'first_name', 'last_name', 'email', )},
'facebook_user': {'fields': ( 'fb_uid', 'fb_email', )}, })
return HttpResponse(serialized_response, mimetype="application/json")
else:
if token and expiration and creation:
new_token = OAuthToken(token=token, issued_at=datetime.fromtimestamp(float(creation)),
expires_at=datetime.fromtimestamp(float(expiration)))
new_token.save()
facebook = Pyfb(FACEBOOK_APP_ID)
facebook.set_access_token(token)
me = facebook.get_myself()
if (type(me.name) == type(unicode())):
try:
#also need to update to the current token
fb_user = FacebookAppUser.objects.get(fb_uid=me.id)
user = fb_user.appuser.user
#response = json.dumps({'status': 'success', 'user':user, 'fb_user':fb_user})
#serialized_response = serializers.serialize('json', [ user, fb_user, ])
#return HttpResponse(me.__dict__)
serialized_response = serializers.serialize('json', [fb_user.appuser, ], relations={
'user': {'fields': ( 'username', 'first_name', 'last_name', 'email', )},
'facebook_user': {'fields': ( 'fb_uid', 'fb_email', )}, })
return HttpResponse(serialized_response, mimetype="application/json")
#return HttpResponse(response, mimetype="application/json")
#if (find_fb_user.appuser.user == request.user):
#find_fb_user.oauth_token = new_token
#find_fb_user.save()
#response = json.dumps({'status': 'success',})
#return HttpResponse(response, mimetype="application/json")
#else:
#response = json.dumps({'status': 'unauthorized',})
#.........這裏部分代碼省略.........
示例11: Pyfb
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
#Your APP ID. You Need to register the application on facebook
#http://developers.facebook.com/
FACEBOOK_APP_ID = 'YOUR_APP_ID'
pyfb = Pyfb(FACEBOOK_APP_ID)
#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
pyfb.authenticate()
#Copy the [access_token] and enter it below
token = raw_input("Enter the access_token\n")
#Sets the authentication token
pyfb.set_access_token(token)
photos = pyfb.get_photos()
print "These are my photos:\n"
for photo in photos:
print photo.picture
#Just call the method next to get the next page of photos!
more_photos = photos.next()
print "\nMore photos:\n"
for photo in more_photos:
print photo.picture
more_more_photos = more_photos.next()
示例12: Pyfb
# 需要導入模塊: from pyfb import Pyfb [as 別名]
# 或者: from pyfb.Pyfb import set_access_token [as 別名]
from django.contrib.auth.models import User
from authentication.models import *
from core.models import *
from django.conf import settings
from pyfb import Pyfb
oauth = Pyfb(settings.FACEBOOK_APP_ID, settings.FACEBOOK_SECRET_KEY)
u = User.objects.get(username='igokulnath')
f = FacebookProfiles.objects.get(user=u)
oauth.set_access_token(f.fbk_token)
api = tweepy.API(oauth)
me = api.me()