Using ArcREST to export Feature Layers

840
4
09-01-2016 10:52 AM
Highlighted
Occasional Contributor

I am writing a python script to run nightly that exports Feature Layers from AGOL to our local drives.  We have a couple of members that are updating their own feature layers, and I am trying to access these.  I can get the script to work using....shAGOL = arcrest.AGOLTokenSecurityHandler(username, password).....if the username and password are the AGOL members.  However, if I try to use the AGOL Administrator username and password, it can't access the members feature layers.  Is there a way to get the script to work using just the Administrator credentials instead of having to ask each member for their passwords?  Any help would be appreciated!  I am very new to ArcREST, so I am sure that I am missing something.

Tags (2)
Reply
0 Kudos
4 Replies
Highlighted
MVP Esteemed Contributor

I am not sure if there is enough to go on.  It could be authentication isn't the issue but how some of the rest of the code is working when logged in as different users, not necessarily an administrator non-administrator issue.  What happens when logged in as an administrator?  Does the script error?  Are the results different than expected?

Reply
0 Kudos
Highlighted
Occasional Contributor

We got it figured out.  It was later on in the coding.  It was a matter of changing the line

user = admin.content.users.user(username=item.owner) to

user = admin.content.users.user(username=username).

It does lead me to another question, though.  The purpose of our python code is to back up the feature layers that others are creating and updating on AGOL.  Right now, the python code looks for a specific ItemID....is there a way to have the code go into a Members content and list all of their feature layers and itemIDs?  This would be ideal since we may not be notified every time someone creates a new layer.  Does that make sense?  I haven't found a script that does it that way.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

I want to say, "yes, you can do it that way," but I want to double check something first.  In the meantime, it might be worth asking this question on the ArcREST Github site.

Reply
0 Kudos
Highlighted
Occasional Contributor

Just to follow up on this, I did get the script working.  It was a matter of adding this piece before the user.exportItem.....

admin = arcrest.manageorg.Administration(securityHandler=shAGOL)
content = admin.content
portal = admin.portals.portalSelf
commUsers = portal.users(start=1, num=100)
commUsers = commUsers['users']

for commUser in commUsers:
                user = admin.content.users.user(commUser.username)
                for userItem in user.items:
                            sItem = userItem.id
                            sName = userItem.name
                            sType = userItem.type
                            sUser = commUser.username
                            if sUser == "YakimaStormwater":
                                        if sType == "Feature Service":