我试图访问我的功能服务的管理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..。
错误:
嗨,马修,
有有很多方法为ArcGIS Online生成一个令牌。我更喜欢的方法是使用应用证书在我的ArcGIS在线组织项目。步骤如下:
将其作为GET或POST请求发送,并应返回一个令牌,该令牌可用于您在ArcGIS Online组织中拥有/共享的所有内容。
我希望这对你有帮助!
卡尔文
我用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;