如何生成一个有效的令牌ArcGIS在线功能服务

1325
2
05-26-2021上午10:09
MatthewFogarty
新贡献者II

我试图访问我的功能服务的管理api,但我无法获得有效的令牌。我看到了这篇文章,就跟着看了(//www.gobook3.com/t5/arcgis-rest-api-questions/generating-token-for-arcgis-online-hosted-se..。),我就能生成一个令牌。但是,当我将该令牌添加到URL以访问管理服务时,它显示为无效令牌。是否有另一种方式我应该生成这个令牌来获得我需要的访问?

生成令牌的URL如下所示:

https://www.arcgis.com/sharing/generateToken?f=json&username=USERNAME&password=PASSWORD&client=requestip

试图访问功能服务管理api的URL如下所示:

https://services6.arcgis.com/qDx.../arcgis/rest/admin/services/Layer_Name/FeatureServer?token=2nt..。

错误:

截图20121-05-26 at 10.08.24 AM.png

标签(5)
2回答
CalvinLietz
通过 Esri贡献者
Esri贡献者

嗨,马修,

有很多方法为ArcGIS Online生成一个令牌。我更喜欢的方法是使用应用证书在我的ArcGIS在线组织项目。步骤如下:

  1. 浏览到您的ArcGIS Online组织的Content选项卡。新增项目->应用类型为“应用”的应用
  2. 进入所创建项目的“项目详细信息”页面,浏览到“设置”选项卡。在页面底部,展开“注册信息”。您应该看到一个AppID和AppSecret。
  3. 转到Oauth2.0令牌URL:https://www.arcgis.com/sharing/rest/oauth2/token?。我们需要的URL参数是:
  • F = json
  • client_id =上面的AppID
  • client_secret =上面的AppSecret
  • Grant_type = client_credentials
  • 过期= 20160(2周,以分钟为单位,这是最大值)

将其作为GET或POST请求发送,并应返回一个令牌,该令牌可用于您在ArcGIS Online组织中拥有/共享的所有内容。

我希望这对你有帮助!

卡尔文

BethLott
通过
新贡献者II

我用RestSharp这样做。不是将令牌附加到请求URL的末尾,而是使用AddHeader方法将令牌添加到请求中。

var client = new RestClient(baseUrl);//服务的url var request = new RestRequest("0/applyEdits", Method.POST);请求。AddHeader("Authorization", $"Bearer {token}");//"token"是传递给方法的参数;我在这个示例请求中留下了方法签名。AddParameter(“f”、“json”);request.AddParameter (editsType.ToString (), jsonAdds);//" jsonadding "是JSON对象类型的另一个参数if (editsType == applyeditstype . adding) //"editsType"是一个自定义enum参数{//允许服务为添加请求创建新的GlobalID。AddParameter(“useGlobalIds”,“假”);} else{//允许更新和删除基于GlobalID而不是基于OBJECTID请求查找记录。AddParameter(“useGlobalIds”,“真正的”);} var response = client.Execute(request); if (response.ErrorException != null) { var gisException = new Exception("Error retrieving response. Check inner details for more info.", response.ErrorException); throw gisException; } return response.Content;
0荣誉