Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Python密钥环与Box API OAuth2结合使用?_Python_Python 3.x_Box Api_Boxapiv2_Python Keyring - Fatal编程技术网

如何将Python密钥环与Box API OAuth2结合使用?

如何将Python密钥环与Box API OAuth2结合使用?,python,python-3.x,box-api,boxapiv2,python-keyring,Python,Python 3.x,Box Api,Boxapiv2,Python Keyring,我对Python和编程非常陌生,我正试图弄明白如何自动化box.com身份验证过程,这让我大吃一惊。任何帮助都将不胜感激 我有下面的代码,这显然不是我的,但来自一个教程。我正试图找出答案 keyring.get_password('Box_Auth', 'mybox@box.com') 我在想mybox@box.com是我的重定向URI吗?但我不知道它在寻找什么,当它要求的盒子授权 这是完整的代码 """An example of Box authentication with externa

我对Python和编程非常陌生,我正试图弄明白如何自动化box.com身份验证过程,这让我大吃一惊。任何帮助都将不胜感激

我有下面的代码,这显然不是我的,但来自一个教程。我正试图找出答案

keyring.get_password('Box_Auth', 'mybox@box.com')
我在想mybox@box.com是我的重定向URI吗?但我不知道它在寻找什么,当它要求的盒子授权

这是完整的代码

"""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)

再说一次,我真的非常感谢任何帮助

我也有同样的问题

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