是否可以生成永不过期的arcgis token

Is it possible to generate arcgis token that will never expire

我是 arcgis 的新手,如果我尝试做的事情不是应该做的事情,请告诉我。

我有一个服务器应用程序,它会定期对某些数据进行分析,然后通过 python arcgis 包将该数据作为 CSV 发布回 arcgis。然后显示在 arcgis 的仪表板上。

我的问题是我找不到生成不会过期的令牌的方法。我更喜欢存储令牌而不是 username/password 并且我不能执行 OAuth2,因为这是定期后台任务...

是否可以生成这样的令牌?

我设法在 arcgis 中注册了一个应用程序,从中我得到了 client_id 和 client_secret,我可以用它来调用 arcgis.com/sharing/rest/oauth2/token 并生成一个令牌,我可以在会话期间使用,但是此令牌不允许我调用 GIS.item.updateGIS.item.publish...

这是我用来生成和使用令牌的代码:

from arcgis.gis import GIS
import json
from urllib3 import PoolManager
from urllib3.exceptions import HTTPError

url = "https://www.arcgis.com/sharing/rest/oauth2/token"

payload = "client_id=my_client_id&client_secret=my_secret&grant_type=client_credentials"
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'accept': "application/json",
    'cache-control': "no-cache", }

pool_manager = PoolManager()

try:
    response = pool_manager.request(method="POST", url=url, headers=headers, body=payload, retries=3)
    token = json.loads(response.data)["access_token"]
    print(token) # Token gets generated without any problem
except HTTPError as e:
    print(str(e))

g = GIS(token=token)
i = g.content.get(my_arcgis_item_id)
i.download("/tmp", file_name="my_file_name") # no permission issues here

device_properties = {
    "title": "test",
    "tags": "test",
    "type": "CSV"}

i.update(item_properties=device_properties, data="/tmp/my_file_name") # <-- this fails

如果我使用通过 REST API 生成的令牌,上面的最后一步将失败。如果我只是来自 https://developers.arcgis.com/dashboard 的 copy/paste 令牌,那么我不会遇到任何授权问题(但是这个令牌是临时令牌...)

解决方案可能是获取使用oauth2生成的授权令牌,然后使用刷新令牌定期重新生成令牌(https://developers.arcgis.com/rest/users-groups-and-items/token.htm)