jhoerr / box-csharp-sdk-v2

A C# client for the Box API (v2).
http://developers.box.com/docs/
11 stars 15 forks source link

Get Users who havent login more then 60 days #57

Open LalitaMittal opened 10 years ago

LalitaMittal commented 10 years ago

I am having requirement to get all users who havent login into the Box.com account more then 60 days. I am using below code

var boxManager = new BoxManager(accessTokenNew);

            EnterpriseUserCollection usercol = new EnterpriseUserCollection();
            usercol = boxManager.GetUsers();
            int count = usercol.TotalCount;
            int usercount = 0;
            for (usercount = 0; usercount < count; usercount++)
            {
                string login = usercol.Entries[usercount].Login;

                var boxManager1 = new BoxManager(accessTokenNew, onBehalfOf: login);
                UserEventCollection eventCol = new UserEventCollection();
                eventCol = boxManager1.GetUserEvents(0);
            }

But every time on eventCol = boxManager1.GetUserEvents(0); , I am getting forbidden error. I am the co-admin of the box.com account. Please let me know what I can do to resolve it.

Best Regards, Lalita Mittal

jhoerr commented 10 years ago

Hi Lalita. Is this issue related to this Stack Overflow question? If so, I'd recommend fetching these events on an enterprise-wide basis instead of for each user. Filtering to just the 'Login' events will save a lot of time.

var boxManager = new BoxManager(accessTokenNew);
var lastSixtyDays = DateTime.UtcNow.AddDays(-60);
var loginEvents = boxManager.GetEnterpriseEvents(lastSixtyDays, null, new[]{ EnterpriseEventType.Login } )
LalitaMittal commented 10 years ago

Hi John,

Yes, this is the same. I tried that way and it is working fine. Thanks a lot for suggesting the way. But my only concern was Looping two times : once for User and second for event. I tried your below method and its working fine. Just wanted to clarify on if “Login” events are the events when user is login into the Box.com.

I appreciate all your support , it helped me a lot in achieving my requirements.

Thanks, Lalita Mittal

From: John Hoerr [mailto:notifications@github.com] Sent: Friday, July 11, 2014 7:41 PM To: jhoerr/box-csharp-sdk-v2 Cc: Lalita Mittal Subject: Re: [box-csharp-sdk-v2] Get Users who havent login more then 60 days (#57)

Hi Lalita. Is this issue related to this Stack Overflow questionhttp://stackoverflow.com/questions/24604374/get-all-users-who-havent-login-into-box-com-more-than-60-days? If so, I'd recommend fetching these events on an enterprise-wide basis instead of for each user. Filtering to just the 'Login' events will save a lot of time.

var boxManager = new BoxManager(accessTokenNew);

var lastSixtyDays = DateTime.UtcNow.AddDays(-60);

var loginEvents = boxManager.GetEnterpriseEvents(lastSixtyDays, null, new[]{ EnterpriseEventType.Login } )

— Reply to this email directly or view it on GitHubhttps://github.com/jhoerr/box-csharp-sdk-v2/issues/57#issuecomment-48734673.

jhoerr commented 10 years ago

Hi Lalita, sorry for the late reply -- I was on holiday last week.

My understanding is that the Login event would indicate any time the user entered their credentials at Box.com. However, this could be done for several reasons, such as using the Box web app, authorizing an external 3rd party application, etc.