I am not familiar with the JavaScript API but I have used the REST API itself.
You might try passing the token as a URL parameter, i.e. &token=#####. That is how you pass it in REST.
In fact I've tried it before. I appended the token to the URL to fetch web map like this:https://www.arcgis.com/sharing/rest/content/items/{webmapId}/data?f=json&token={token} Then I got a json object as following:
{
"baseMap": {
"baseMapLayers": [
{
"id": "World_Street_Map_1271",
"opacity": 1,
"url": "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
"visibility": true
}
],
"title": "World_Street_Map"
},
"operationalLayers": [
{
"id": "USA_States_Generalized_9320",
"layerDefinition": {
"drawingInfo": {
"renderer": {
"symbol": {
"color": [
255,
214,
180,
0
],
"outline": {
"color": [
251,
164,
93,
255
],
"style": "esriSLSSolid",
"type": "esriSLS",
"width": 0
},
"style": "esriSFSSolid",
"type": "esriSFS"
},
"type": "simple"
}
}
},
"mode": 1,
"opacity": 1,
"popupInfo": {
"description": null,
"fieldInfos": [
{
"fieldName": "FID",
"format": {
"digitSeparator": true,
"places": 0
},
"isEditable": true,
"label": "FID",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "STATE_NAME",
"format": null,
"isEditable": true,
"label": "STATE_NAME",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "SUB_REGION",
"format": null,
"isEditable": true,
"label": "SUB_REGION",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "STATE_ABBR",
"format": null,
"isEditable": true,
"label": "STATE_ABBR",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "POP2010",
"format": {
"digitSeparator": true,
"places": 0
},
"isEditable": true,
"label": "POP2010",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "POP10_SQMI",
"format": {
"digitSeparator": true,
"places": 2
},
"isEditable": true,
"label": "POP10_SQMI",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "POP2012",
"format": {
"digitSeparator": true,
"places": 0
},
"isEditable": true,
"label": "POP2012",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "POP12_SQMI",
"format": {
"digitSeparator": true,
"places": 2
},
"isEditable": true,
"label": "POP12_SQMI",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
{
"fieldName": "WHITE",
"format": {
"digitSeparator": true,
"places": 0
},
"isEditable": true,
"label": "WHITE",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
},
// omit some other fieldNames to shorten the text
,
{
"fieldName": "SQMI",
"format": {
"digitSeparator": true,
"places": 2
},
"isEditable": true,
"label": "SQMI",
"stringFieldOption": "textbox",
"tooltip": "",
"visible": true
}
],
"mediaInfos": [],
"showAttachments": true,
"title": "USA_States_Generalized: "
},
"title": "USA_States_Generalized - USA_States_Generalized",
"url": "http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServer/0",
"visibility": false
}
],
"version": "1.9.1"
}
However, we expected to get an object that contains "map" property to add some manipulations on the map. I don't know what this returned json is used for. It seems to be a definition of the web map.