Download files from shared folder (python)
Hey there,
Here is my scenario:
I need to programmatically access new files from a shared_folder and download them to S3. Here's what I have done so far:
1) - I have added this "shared folder" to my favorites
2) - I have created an APP using python with JWTAuth.
3) - I have allowed all the scope settings for the APP.
4) - In python I have created a new client using the as_user method.
5) - When I attempt to list the objects in my "favorites" "Collection" everything appears apart from the shared folder
6) - When I do the same thing using the developer token, I can see the files in the shared folder.
I have noticed there is a "get_shared_item" method, but this returns a 404. Even when called from the impersonated_client.
So, my question is.. how do I access files from a shared folder when I'm impersonating a user programmatically using python?
Thanks
-
Hey There,
Yes I did... here's a snippet just for you..
def download_files_from_box():
log.info('Looking for new files to download from box')
p_key_path = os.path.join("PATH TO YOUR SSH KEY")
box_client_id = os.getenv("BOXCOM_CLIENT_ID")
box_client_secret = os.getenv("BOXCOM_CLIENT_SECRET")
box_user_id = os.getenv("BOXCOM_USER_ID")
box_enterprise_id = os.getenv("BOXCOM_ENTERPRISE_ID")
box_passphrase = os.getenv("BOXCOM_PASSPHRASE")
auth = JWTAuth(
client_id=box_client_id,
client_secret=box_client_secret,
user=box_user_id,
jwt_key_id="YOURKEY",
rsa_private_key_file_sys_path=p_key_path,
rsa_private_key_passphrase=box_passphrase,
enterprise_id=box_enterprise_id
)
auth.authenticate_user()
user_client = Client(auth)
# The only collection you can have is Favourites. The folder that
# has been shared with us has been added as a favourite on our side.
favourites_id = None
collections = user_client.collections()
for collection in collections:
if collection.name == 'Favorites':
favourites_id = collection.id
# Grab a list of available files to download
bulk_data_folder_id = None
file_id_list = []
if favourites_id:
items = user_client.collection(collection_id=favourites_id).get_items()
for item in items:
if item.name == 'NAME OF YOUR FOLDER':
bulk_data_folder_id = item.id
投稿コメントは受け付けていません。
コメント
3件のコメント