我的应用程序在谷歌注册,我已经启用了联系人API。在
在第一个视图中,我获得了访问令牌,并将用户重定向到Google确认页面,在该页面上,将提示用户授予其联系人的访问权限:
SCOPE = 'https://www.google.com/m8/feeds/'
CLIENT_ID = 'xxxxxxxx'
CLIENT_SECRET = 'xxxxxxxxx'
APPLICATION= 'example.com'
USER_AGENT = 'dummy-sample'
APPLICATION_REDIRECT_URI = 'http://example.com/oauth2callback/'
def import_contacts(request):
auth_token = gdata.gauth.OAuth2Token(
client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
scope=SCOPE, user_agent=USER_AGENT)
authorize_url = auth_token.generate_authorize_url(
redirect_uri=APPLICATION_REDIRECT_URI)
return redirect(authorize_url)
如果用户单击“允许”,则谷歌重定向到我的处理程序,该处理程序将检索联系人:
^{pr2}$
正如您所看到的,我的问题是如何在第二个视图中获取auth\u令牌对象,因为这段代码在auth_token.get_access_token(url.query)
行失败。
我尝试过多个选项,比如将对象放入会话中,但没有成功,但它不可序列化。我也尝试了gdata.gauth.token_to_blob(auth_token)
,但是我只能检索令牌字符串,而不能检索对象。使用gdata.gauth.ae_save()
和{}似乎在某种程度上需要googleappengine。在
我看到的另一种方法是在第一个Django视图中使用访问令牌直接请求联系人,而不是用代码交换令牌:
r = requests.get('https://www.google.com/m8/feeds/contacts/default/full?access_token=%s&alt=json&max-results=1000&start-index=1' % (self.access_token))
但这并不是将用户重定向到google页面,这样他们就可以明确表示同意了。相反,它直接使用令牌作为凭据获取联系人。这是惯例吗?你怎么认为?我认为第一种方法是首选方法,但首先我必须设法获得auth_token对象。。在
Tags:
对象用户comclienttokenauth视图urlapplicationgoogle联系人页面重定向gdatagauth1条回答网友
1楼 ·
发布于 2023-03-06 23:31:07
最后,我能够序列化对象并将其放入会话中,这不是一个安全的方法,但至少它会为我指明正确的方向,以便我可以继续我与社交应用程序相关的业务逻辑。在
import gdata.contacts.client
def import_contacts(request):
auth_token = gdata.gauth.OAuth2Token(
client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
scope=SCOPE, user_agent=USER_AGENT)
authorize_url = auth_token.generate_authorize_url(
redirect_uri=APPLICATION_REDIRECT_URI)
# Put the object in the sesstion
request.session['auth_token'] = gdata.gauth.token_to_blob(auth_token)
return redirect(authorize_url)
def oauth2callback(request):
code = request.GET.get('code', '')
redirect_url = 'http://myapp.com/oauth2callback?code=%s' % code
url = atom.http_core.ParseUri(redirect_url)
# Retrieve the object from the session
auth_token = gdata.gauth.token_from_blob(request.session['auth_token'])
# Here is the tricky part: we need to add the redirect_uri to the object in addition
auth_token.redirect_uri = APPLICATION_REDIRECT_URI
# And this was my problem in my question above. Now I have the object in the handler view and can use it to retrieve the contacts.
auth_token.get_access_token(url.query)
# The second change I did was to create a ContactsClient instead of ContactsService
client = gdata.contacts.client.ContactsClient(source=APPLICATION)
auth_token.authorize(client)
feed = client.GetContacts()
all_emails = []
for i, entry in enumerate(feed.entry):
# Loop and fill the list with emails here
...
return render_to_response('xxx/import_contacts.html', {'all_emails': all_emails},
context_instance=RequestContext(request))
cheap sildenafil 100mg discount viagra canadian pharmacy viagra soft gel capsules
why do i get watery baginal discharge when im in keflex cephalexin for ear piercing infection keflex overdose
does keflex cause c diff why do i get watery baginal discharge when im in keflex bactrim and keflex on birth control
cephalexin expired 2 years ago cephalexin dogs uti cephalexin eye infection
cephalexin dog cephalexin for hidradenitis suppurativa cephalexin gram positive or negative
what std does amoxicillin treat how long amoxicillin liquid amoxicillin dosage for cats in ml
clavulanic acid is combined with amoxicillin because does amoxicillin treat a sinus infection can you take amoxicillin for covid
augmentin 850 mg prospect contre indication d’augmentin augmentin suspension 400 mg dosis
can i take augmentin with tamiflu augmentin marketing augmentin suspensГЈo oral
can dogs take human amoxicillin amoxicillin for herpes amoxicillin for vaginal infection
amoxicillin ingredients is amoxicillin penicillin based amoxicillin for pregnancy
ciprofloxacin vs keflex ciprofloxacin dog dose mg/kg can ciprofloxacin make you tired
dog prednisone dosage by weight prednisone 20 mg for uti prednisone and paxlovid
how does doxycycline work for acne why can’t you lie down after taking doxycycline does doxycycline treat tooth infection
doxycycline medicine side effects of taking metronidazole and doxycycline together doxycycline perioral dermatitis before and after
prednisone patient teaching long term effects of prednisone in dogs hydrocortisone vs prednisone
best time of day to take prednisone can i take antacids with prednisone prednisone tinnitus
ciprofloxacin for sinus infection ciprofloxacin safe in pregnancy what foods to avoid when taking ciprofloxacin
strep throat augmentin augmentin for ear infection augmentin dosing for children
what is azithromycin 250 mg tablets used for azithromycin adverse effects azithromycin with penicillin allergy
cephalexin 250 mg para niГ±os can i give my cat cephalexin 250 mg cap cephalexin 500mg
how to get viagra us can you buy sildenafil over the counter in uk can you buy female viagra over the counter
tadalafil 10mg prices cialis for low price cialis super active vs cialis
is tadalafil available in the us best tadalafil cialis over the counter 2018
buy viagra australia how can i get generic viagra sildenafil australia buy
100 mg cialis tadalafil 20 mg soft chewable tablets cialis free
best price for generic viagra sildenafil discount price sildenafil india pharmacy
buy viagra 500mg buy generic viagra 100mg online sildenafil 20mg prescription cost
poetry analysis essay example good persuasive essay topics essaywriting service
apa essay format legitimate essay writing service parts of an essay
buy college essays essay writers for hire i need help to write an essay
college essay helper apa style essay write my essay help
buy essay cheap quality custom essay custom essay services
what is the best online essay writing service evaluation essay college essay writers block
evaluation essay mba admission essay writing service cheap essay writing service usa
online pharmacy indomethacin cytotec pharmacy best cialis online pharmacy
pharmacy without prescription people’s pharmacy generic wellbutrin aciphex online pharmacy
online pharmacy that fill oxycodone phentermine online prescription online pharmacy rx pharmacy shop coupon code
rx options pharmacy help desk dapoxetine schedule rx pharmacy one source
trazodone online pharmacy best drug store foundation plavix pharmacy price
motilium online pharmacy soma us pharmacy Lamivudin (Cipla Ltd)
promethazine with codeine pharmacy price wellbutrin pharmacy online online pharmacy selling oxycodone
Super P-Force pharmacy direct gb propecia Feldene
best online xanax pharmacy online pharmacy no prescription ultram vipps online pharmacy viagra
cialis online pharmacy australia online pharmacy usa viagra online pharmacy no prescription needed vicodin
sildenafil vs tadalafil reddit tadalafil 10mg price genpharma tadalafil
tadalafil normal dose how long does tadalafil last tadalafil head and neck
royal honey vip tadalafil tadalafil 5mg price canada how long does it take for tadalafil daily to work
how many tadalafil can i take tadalafil sale how long does tadalafil last in the body
tadalafil losartan combination therapy tadalafil cost per pill where can i get tadalafil
can you take tadalafil after drinking alcohol how long does 10mg of tadalafil last tadalafil 20mg vs sildenafil 100mg
tadalafil how much does it cost is 10 mg of tadalafil enough what is tadalafil generic for
sildenafil citrate & tadalafil tablets tadalafil nitric oxide compare sildenafil and tadalafil
can you take tylenol with tadalafil what is tadalafil used for in bodybuilding can i take 10 mg tadalafil daily
tadalafil sublingual tablet 20mg online pharmacy tadalafil how long does tadalafil 5mg last
prescription for tadalafil tadalafil vs cialis can you take sildenafil and tadalafil at the same time
tadalafil 5mg coupon tadalafil controlled que es tadalafil
tadalafil patent order tadalafil without prescription 40 mg of tadalafil
what happens if you take 2 tadalafil tadalafil expiration tadalafil research chemical
tadalafil 60 mg can i take 10mg of tadalafil daily tadalafil and coffee
can you take tadalafil after drinking alcohol tadalafil troches tadalafil natural
grapefruit and tadalafil can you buy tadalafil online can you take 10mg tadalafil daily
is 10mg of tadalafil effective tadalafil fj4 cialis vs tadalafil
cobalt research tadalafil tadalafil (cialis tadalafil liquid drops dosage
tadalafil user reviews tadalafil deutschland tadalafil 10mg reviews
tadalafil tablets 20mg female take 5 ml of tadalafil mail order tadalafil