Unable to access item on ArcGIS Online from Sandbox

993
3
03-26-2021 08:09 AM
MichaelBessette
New Contributor

I feel like this is a ridiculously noob question, but I'm stuck so here goes...

I'm new to ESRI development and I'm following instructions for the Display a Map tutorial. However, I'm unexpectedly blocked at the Create a Map step.

When coding in either CodePen or the ArcGIS sandbox, I get the following logon prompt upon inserting the API: "Please sign in to access the item on ArcGIS Online (item)". When I put in my ArcGIS credentials, I receive an error that "The username or password you entered is incorrect". This is false. I'm currently logged into ArcGIS Online with those same credentials. I am absolutely certain that my ArcGIS logon is correct. 

The issue I'm having is very similar to this one from 2020, but in my case my work is all hosted online and not run locally. This ESRI sample from that ticket works for me, but I'm not sure what that means. 

There are a lot of APIs in my developer dashboard, so perhaps I'm using the wrong one? I've tried inserting the following keys, though my presumption is that the top one is what I want since that's the tutorial I'm working on.

  • ArcGIS API for JavaScript
  • ArcGIS Web AppBuilder
  • ArcGIS Experience Builder

Any help or insight is appreciated! 

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

It sounds like you're  trying to access that's on an organizational site on ArcGIS.com (youcompany.maps.arcgis.com) When I have to access items on my organization, I have to use OAuthInfo and IdentityManager to log in.

This is an example of the code I use to get items that aren't public

    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/identity/OAuthInfo",
      "esri/identity/IdentityManager"
    ], function (Map, MapView, FeatureLayer, OAuthInfo, identityManager) {
      let layer, map, view;
      const portalUrl = 'https://yourCompany.maps.arcgis.com';
      const info = new OAuthInfo({
        appId: "xxxxxxxxxxxxxxx", //*** Your Client ID value goes here ***//
        popup: false // inline redirects don't require any additional app configuration
      });
      identityManager.registerOAuthInfos([info]);

      // send users to arcgis.com to login
      identityManager.getCredential(portalUrl);
      identityManager.checkSignInStatus(portalUrl).then(function () {
        layer = new FeatureLayer({
          portalItem: {
            id: "itemID"
          },
          outFields: ["*"]
        });
        map = new Map({
          basemap: 'oceans',
          layers: [layer]
        });
        view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-153, 63],
          zoom: 4,
          popup: {
            autoOpenEnabled: false
          }
        });
      });
    });

 

0 Kudos
MichaelBessette
New Contributor

Thank you for your great reply @KenBuja ! 

Unfortunately, it doesn't help my immediate issue because I'm not creating on a corporate site. I'm accessing ArcGIS on my home computer and via my own personal account, through which I am doing nothing more than following the simple instructions in the 'hello world' demo linked above. Which is why I'm so confused that this isn't working. 

Having said that, I will eventually be developing content on an organizational server, at which time your code may be really useful. So genuinely, thank you. 🙂

0 Kudos
SanthoshkumarRavi
New Contributor

Did it work for you? I am also facing similar issue.

0 Kudos