L07_CreateUserAddToGroupShareContentWithGroup

In [1]:
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "<enter username here>", "<password>")
In [3]:
map = gis.map()
In [10]:
if gis.users.search("demo_user2") == 0:
    demo_user1 = gis.users.create(username = 'demo_user2',
                                password = '0286eb9ac01f',
                                firstname = 'demon',
                                lastname = 'user',
                                email = 'demoUser@esri.com',
                                description = 'Demonstrating how to create users using ArcGIS Python API',
                                role = 'org_user',
                                provider = 'portal')
else:
    print("User demo_user2 exists")
User demo_user2 exists
In [9]:
geocaching_group = gis.groups.create(title='Recreational geocaching',
                                    tags = 'hobby, geocaching, gps, hide n seek',
                                    description = 'Group to share your landmarks and games',
                                    snippet = 'Share your GPX tracks as feature layers here',
                                    access = 'org',
                                    is_invitation_only = 'False',
                                    thumbnail = r'')
geocaching_group
Out[9]:
Recreational geocaching

Summary: Share your GPX tracks as feature layers here
Description: Group to share your landmarks and games
Owner: PortalAdmin
Created: March 01, 2017
In [11]:
geocaching_group.add_users([ 'demo_user1','demo_user2'])
members = geocaching_group.get_members()

members
Out[11]:
{'admins': ['PortalAdmin'],
 'owner': 'PortalAdmin',
 'users': ['demo_user1', 'demo_user2']}
In [12]:
search_result_USA = gis.content.search(query="title:USA*")
search_result_USA
Out[12]:
[<Item title:"USA Soils Runoff" type:Image Service owner:esri_livingatlas>,
 <Item title:"USA USFS Lands" type:Map Service owner:esri_livingatlas>,
 <Item title:"2016 USA Clothing/Accessory Store Market Opportunity" type:Map Service owner:esri_livingatlas>,
 <Item title:"USA Forest Type" type:Image Service owner:esri_livingatlas>,
 <Item title:"USA Bighorn Sheep GAP Range" type:Image Service owner:esri_livingatlas>,
 <Item title:"2016 USA Home Improvement Spending" type:Map Service owner:esri_livingatlas>,
 <Item title:"USA California Condor GAP Species Range" type:Image Service owner:esri_livingatlas>,
 <Item title:"USA Parks" type:Feature Service owner:esri_livingatlas>,
 <Item title:"2016 USA Average Household Size" type:Map Service owner:esri_livingatlas>,
 <Item title:"USA Freeway System" type:Feature Service owner:esri_livingatlas>]
In [13]:
first_item = search_result_USA[0]
known_item_id = first_item.id
known_item_id
Out[13]:
'e9ac472da84441d8a91ea80044a9ade9'
In [15]:
USA_Soils = gis.content.get(known_item_id)
USA_Soils.access
Out[15]:
'shared'
In [20]:
USA_Soils.share(groups=geocaching_group.id)
Out[20]:
{'itemId': 'e9ac472da84441d8a91ea80044a9ade9',
 'notSharedWith': ['e47fe2a75f554110a96c270d6c61a9aa']}
In [18]:
USA_Soils.unshare
Out[18]:
<bound method Item.unshare of <Item title:"USA Soils Runoff" type:Image Service owner:esri_livingatlas>>
In [ ]: