繁体   English   中英

如何在python中获取OAuth访问令牌?

[英]How do I get an OAuth access token in python?

(我在超级用户上问了这个问题,但没有回复...)

我正在尝试按照Dropta API的教程访问http://taught-process.blogspot.com/2012/05/asdlasd-asda-sd-asd-asdasd.html

但是当我到达最后一部分时

#Print the token for future reference
print access_token

我得到的是

<dropbox.session.OAuthToken object at 0x1102d4210>

我如何获得实际令牌? 它应该看起来像:

oauth_token_secret=xxxxxxx&oauth_token=yyyyyyy

(我在Mac上)

环顾对象的属性和方法,这样做就可以在对象上应用“dir”。 在你的情况下:

dir(access_token)

我很确定你会在这个对象中找到能够为你提供所需令牌的东西。

你有合适的对象,是的。 但是你正在处理一个类的实例。

<dropbox.session.OAuthToken object at 0x1102d4210>

这是Dropbox SDK为您创建的OAuthToken对象的一个​​实例。 此令牌似乎有两个属性: keysecret 这些将是您的令牌密钥和秘密。 这就是你所追求的。

您可以像这样访问它们:

print access_token.key
print access_token.secret

http://taught-process.blogspot.com/2012/05/asdlasd-asda-sd-asd-asdasd.html上使用与Dropbox API相同的教程

结束以下适用于我的脚本

# Include the Dropbox SDK libraries
from dropbox import client, rest, session

# Get your app key and secret from the Dropbox developer website
APP_KEY = '3w7xv4d9lrkc7c3'
APP_SECRET = '1v5f80mztbd3m9t'

# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
ACCESS_TYPE = 'app_folder'

sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
request_token = sess.obtain_request_token()
url = sess.build_authorize_url(request_token)

# Make the user sign in and authorize this token
print "url:", url
print "Please visit this website and press the 'Allow' button, then hit 'Enter' here."
raw_input()

# This will fail if the user didn't visit the above URL
access_token = sess.obtain_access_token(request_token)

#Print the token for future reference
print access_token.key
print access_token.secret

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM