You will learn: how to use the ArcGIS API for Python to programmatically change the sharing settings for your layers.
You can share layers, maps, and other items saved in your ArcGIS for Developers account with the public or choose to keep your content private. Until actively shared, items are not visible to others and do not appear in search results. Public items are accessible to everyone. Developers should keep in mind that an item's sharing settings will impact any apps consuming that item. For example, if you have an app that's using a web map, and the web map is later set to 'private', the app will not display that map. In this quick lab, you'll explore how to control the sharing settings with the ArcGIS API for Python. You can learn much more about sharing your layers and using groups by accessing ArcGIS Online documentation.
Complete the Create a new dataset DevLab. You will use the output feature layer to complete this DevLab.
Go to the Esri Jupyter Notebook and click New > Python 3 to create a new notebook.
In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.
Add the following code in a cell to import the ArcGIS API for Python.
from arcgis.gis import *
Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace
password with your own credentials.
dev_gis = GIS("https://www.arcgis.com", "username", "password")
Search for the Griffith Park Access layer created in the Create a new dataset DevLab.
feature_layer_srch_results = dev_gis.content.search(query='title: "Griffith*" AND type: "Feature Service"') feature_layer_srch_results
Retrieve the feature layer collection item from the list of results.
feature_layer_coll_item = feature_layer_srch_results feature_layer_coll_item
Check the current sharing permissions of the layer.
Update the sharing permissions of the layer so that it's available to everyone.
Check that the permissions have been updated.
Your notebook should now look something like this.