Trouble Accessing Box Files through Python Script (OAUTH2)
I am working on a script for my enterprise that will automatically index files that were uploaded into specific folders into a csv. I'm an experienced python developer, but I don't have much knowledge about authentication. Right now, I am having issues accessing the client directory/repository with the following script.
from boxsdk import OAuth2, Client
oauth = OAuth2(
client_id='######',
client_secret='######',
store_tokens='store_tokens',#your_store_tokens_callback_method, Am I passing the correct argument here?
)
auth_url, csrf_token = oauth.get_authorization_url('http://YOUR_REDIRECT_URL')#where is my redirect URL? Do I need one?
def store_tokens(access_token, refresh_token):
# store the tokens at secure storage (e.g. Keychain)
OAuth2.store.AccessTokenStore.save_token(access_token)
OAuth2.store.AccessTokenStore.save_token(refresh_token)
# Make sure that the csrf token you get from the `state` parameter
# in the final redirect URI is the same token you get from the
# get_authorization_url method.
assert 'THE_CSRF_TOKEN_YOU_GOT' == csrf_token
access_token, refresh_token = oauth.authenticate('YOUR_AUTH_CODE')
client = Client(oauth)
Running this gives me:
Traceback (most recent call last):
File "C:/Users/syoung/PycharmProjects/IndexingProject/boxIndex.py", line 21, in
assert 'THE_CSRF_TOKEN_YOU_GOT' == csrf_token
AssertionError
If anyone could help me debug this or guide me to some more detailed references that would be much appreciated. I need to have access by the end of this script in order to call .folder.getItems() on client.
Please sign in to leave a comment.
Comments
0 comments