2017-12-01 45 views
1

私はPythonとプログラミングには新しく、box.com認証プロセスを自動化する方法を理解しようとしています。それは私のお尻を蹴っています。どんな助けもありがとう!Box API OAuth2と一緒にPython Keyringを使用するにはどうすればよいですか?

私は明らかに私のものではなく、チュートリアルから来たこのコードを持っています。私は把握しようとしています

keyring.get_password('Box_Auth', '[email protected]') 

私は[email protected]が私のリダイレクト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', '[email protected]') 
refresh_token = keyring.get_password('Box_Refresh', '[email protected]') 
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', '[email protected]', access_token) 
keyring.set_password('Box_Refresh', '[email protected]', 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) 

ですが、私は任意の助けを本当に感謝します!

答えて

1

私はまったく同じ問題を抱えていました。

アクセストークンと更新トークンが必要です。 hereこれらの生成方法をお読みください。

関連する問題