You will learn: how to use the ArcGIS API for Python to programmatically change the sharing settings for your layers.
You can publicly share layers, maps, and other items saved in your ArcGIS for Developers account. 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 Import Data tutorial before you begin.
Go to Esri Juptyter Notebooks 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 GIS
Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace
password with your own credentials.
gis = GIS("https://www.arcgis.com", "username", "password")
Search for the Trialheads feature layer created as a challenge in the Import Data tutorial.
search_results = gis.content.search(query='title: "Trailheads*" AND type: "Feature Service"') search_results
Retrieve the feature layer collection item from the list of results.
feature_layer_item = search_results feature_layer_item
Check the current sharing permissions of the layer by visiting its URL,
Update the sharing permissions of the layer so that it's available to everyone.
Check the feature layer URL that the permissions have been updated.
Your notebook should now look something like this.