如何将Python键架与Box Api OAuth2结合使用



我是Python和编程的新手,我正在尝试弄清楚如何自动化Box.com身份验证过程,并且踢了我的屁股。任何帮助将不胜感激!

我在下面有此代码,显然不是我的,但来自教程。我想找出

keyring.get_password('Box_Auth', 'mybox@box.com')

我认为mybox@box.com是我的重定向uri吗?但是我不确定当它要求box_auth时要寻找什么。

这是完整的代码

"""An example of Box authentication with external store"""
import keyring
from boxsdk import OAuth2
from boxsdk import Client
CLIENT_ID = ''
CLIENT_SECRET = ''

def read_tokens():
"""Reads authorisation tokens from keyring"""
# Use keyring to read the tokens
auth_token = keyring.get_password('Box_Auth', 'mybox@box.com')
refresh_token = keyring.get_password('Box_Refresh', 'mybox@box.com')
return auth_token, refresh_token

def store_tokens(access_token, refresh_token):
"""Callback function when Box SDK refreshes tokens"""
# Use keyring to store the tokens
keyring.set_password('Box_Auth', 'mybox@box.com', access_token)
keyring.set_password('Box_Refresh', 'mybox@box.com', refresh_token)

def main():
"""Authentication against Box Example"""
# Retrieve tokens from secure store
access_token, refresh_token = read_tokens()
# Set up authorisation using the tokens we've retrieved
oauth = OAuth2(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
access_token=access_token,
refresh_token=refresh_token,
store_tokens=store_tokens,
)
# Create the SDK client
client = Client(oauth)
# Get current user details and display
current_user = client.user(user_id='me').get()
print('Box User:', current_user.name)

再次,我真的很感谢任何帮助!

我遇到了完全相同的问题。

您将需要一个访问令牌和刷新令牌。在这里阅读如何生成这些。

最新更新