How can i connect to the new Layer (My data) that is in the privet me mode from my javascript code? it asked me the Username and password, Itried my Acount password but it didnt work?also is there a way to add user and pasword name at the end of service url in the jason script?
like:
https://services7.arcgis.com/vmdU9JnBFQEei09w/arcgis/rest/services/trailheads/FeatureServer /user/pass
If you are creating a web application using the ArcGIS API for JavaScript, and you try to load a layer that has its sharing level set to "Owner", then yes, when you load that page, the API will try to load that layer; it will find that the sharing level is Owner and will open a login popup for you to login with. As long as the username and password are the same account that the layer is owned by, the layer will load after correct login.
We understand that you tried this, and it still failed to load. This would require just a little bit more troubleshooting. It's possible that the login popup you're getting is for some other resource in your app that is not shared with your account that you logged in with. If you comment out the loading of that layer, and you are still getting that login popup, that would help narrow it down. The idea here is to keep testing until you find the layer that is failing to load, then you can adjust (or request to adjust) the sharing level of that resource. We would recommend you comment out all ArcGIS Online resources, then commenting them back in one at a time, or in groups, in order to find those resources that are opening the login modal and why.
In most cases, that should solve the problem.
We see that you're also asking a question about how to make a private, un-shared layer visible inside your application without requiring user login. There are a few techniques for keeping resources private, and still exposing them to selected applications. One way is to use a proxy. See this document for more information. Go to this page and scroll down to the section called "Application logins". https://developers.arcgis.com/javascript/latest/guide/secure-resources/Using a proxy is a secure and supported way to accomplish this. It is not recommended to pass your login name and password credentials to the app/page as URL parameters in the clear. If you have difficulties or questions in setting this up, please contact Technical Support.
Also, we have a GeoNet community forum specifically for the ArcGIS API for JavaScript. The global community of folks using that API use that forum for Q&A. You will find the best answers and quickest replies there. https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/content
Here's a tip for troubleshooting which layer might be causing your problem with the login window: