cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python API

Python API

AdanHerrera
Explorer | Level 3
Go to solution

I'm working with Python & API v2

I need the following information:
If I have a shared folder with several users, is it possible to obtain a record of the users who have visited or downloaded the files?

 

 

---------------------
I was reading this information but I do not know if it's what I'm looking for.

 

class dropbox.sharing.UserFileMembershipInfo (access_type = None, user = None, permissions = None, initials = None, is_inherited = None, time_last_seen = None)
Bases: dropbox.sharing.UserMembershipInfo

The information about a user member of the shared content with an appended last seen timestamp.

Variables: time_last_seen - The UTC timestamp of when the user has last seen the content, if they have.

 

thanks!

2 Accepted Solutions

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

It looks like you have the right basic idea, but there are a few things to note:

- You have 'none' instead of 'None'.

- You can filter by category, which in this case would be 'dropbox.team_log.EventCategory.file_operations'.

- You can filter by time, which can be good as without a time filter you may have to parse through more events than desired.

- You need to check GetTeamEventsResult.has_more, and call back to team_log_get_events_continue if it's True.

 

So, for example, to look for file_download events from the past week, that might look like:

 

import datetime

import dropbox

access_token = '...'
dbx_team = dropbox.DropboxTeam(access_token)
account_id = 'dbid:...'
time_range = dropbox.team_common.TimeRange(
    start_time=datetime.datetime.now() - datetime.timedelta(days=7))

def handle_events(events):
    print("Processing %s events..." % len(events))
    for event in events:
        if event.event_type.is_file_download():
            print(event)

result = dbx_team.team_log_get_events(
    limit=1000,
    account_id=account_id,
    time=time_range,
    category=dropbox.team_log.EventCategory.file_operations)
handle_events(result.events)

while result.has_more:
    result = dbx_team.team_log_get_events_continue(result.cursor)
    handle_events(result.events)

View solution in original post

Greg-DB
Dropbox Staff
Go to solution
1. No, unfortunately there isn't a way to filter by path across all members, but I'll pass this along as a feature request.

2. Also no, it's not possible to filter to a specific event type, but we'll consider this a feature request as well.

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution

The UserFileMembershipInfo object is used in SharedFileMembers, which is returned by sharing_list_file_members. That only applies to specific files that have been shared individually, not to files inside shared folders. That being the case, it sounds like this isn't what you're looking for in your scenario.

 

There isn't an equivalent property for files in shared folders, though if you're using a Dropbox Business API app with "team auditing" access , you can get 'file_download' events from team_log_get_events and team_log_get_events_continue.

AdanHerrera
Explorer | Level 3
Go to solution

Thanks  Greg for your time.

1) I was looking into UserFileMembershipInfo and get some value information.

 

2) I'm working now with Dropbox Business API app "team auditing" access, you can please show me how can I get the 'File_download' events. I don't know how to do,  I was trying this:

 

import dropbox

token= '    '
dbx_team = dropbox.DropboxTeam(token)
Resultado = dbx_team.team_log_get_events(limit=1000, account_id=u'dbid:fsfdsddf', time=None, category=none)
print(Resultado)

Greg-DB
Dropbox Staff
Go to solution

It looks like you have the right basic idea, but there are a few things to note:

- You have 'none' instead of 'None'.

- You can filter by category, which in this case would be 'dropbox.team_log.EventCategory.file_operations'.

- You can filter by time, which can be good as without a time filter you may have to parse through more events than desired.

- You need to check GetTeamEventsResult.has_more, and call back to team_log_get_events_continue if it's True.

 

So, for example, to look for file_download events from the past week, that might look like:

 

import datetime

import dropbox

access_token = '...'
dbx_team = dropbox.DropboxTeam(access_token)
account_id = 'dbid:...'
time_range = dropbox.team_common.TimeRange(
    start_time=datetime.datetime.now() - datetime.timedelta(days=7))

def handle_events(events):
    print("Processing %s events..." % len(events))
    for event in events:
        if event.event_type.is_file_download():
            print(event)

result = dbx_team.team_log_get_events(
    limit=1000,
    account_id=account_id,
    time=time_range,
    category=dropbox.team_log.EventCategory.file_operations)
handle_events(result.events)

while result.has_more:
    result = dbx_team.team_log_get_events_continue(result.cursor)
    handle_events(result.events)

AdanHerrera
Explorer | Level 3
Go to solution

Perfect.

 

1- In this case you are filtering by (account_id) and getting the events of a specific user, but we can do the same filtering for example by a folder and getting the events of the users in this path?

 

2- In the result I see this event EventType(u'file_download', FileDownloadType(description=u'Downloaded files and/or folders')), could it be programmed so that it only prints this type of events?

 

 

Thanks again, I hope I'm not asking a lot of questions

Greg-DB
Dropbox Staff
Go to solution
1. No, unfortunately there isn't a way to filter by path across all members, but I'll pass this along as a feature request.

2. Also no, it's not possible to filter to a specific event type, but we'll consider this a feature request as well.

John112233
New member | Level 2
Go to solution

i am also searching for the same problem solution altough i'm reading a book to master python named as Python data science handbook PDF

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    John112233 New member | Level 2
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    AdanHerrera Explorer | Level 3
What do Dropbox user levels mean?