案例:如何生成带权限的token
更新时间: 2023-08-29 14:27:47
阅读 2694
案例:如何生成带权限的token
注:目前saas版本不支持集成。
以公开环境为例
接口网址:https://netease.youdata.163.com/
接口后缀:api/dash/util/genToken
请求方式:post
提交内容:
{
"tokenType": "tokenKey",
"key": "个人token—key",
"openRp": true,
"resourcePermissions":[
{
"projectId": 项目id,
"resourceType": "NEW_REPORT",
"permissions": ["view"],
"resourceId":报告id
}
],
"filterMap":
{
"数据链接ID":[
{
"filterType": "listFilter",
"selectType": "select",
"database": "数据库名",
"tableName": "数据表名",
"filter":
{
"dim":
{
"field": "目的省",
"dataType": "String"
},
"select": ["吉林"]
}
}
]
}
}
个人token—key获取
项目iD,报告ID获取
数据链接ID,数据表明,筛选字段,下属条件字段获取
示例:
import requests as re
import json
def get_token(host, post_json):
data = json.dumps(post_json)
headers = {
"content-type": "application/json; charset=UTF-8",
"user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36",
"x-requested-with": "XMLHttpRequest",
"accept": "text/plain, */*; q=0.01",
"accept-encoding": "gzip, deflate, br"
}
api_url = 'api/dash/util/genToken'
if "https://" in host:
url = host + api_url
else:
url = "https://" + host + api_url
back = json.loads(re.post(url=url, headers=headers, data=data).text)["result"]
return back
host = 'https://demo1.youdata.com/dash/folder/1?rid=80751'
post_json = {
"tokenType": "tokenKey",
"key": "16195899946238877320e89fdb6554f46a1a8",
"openRp": true,
"resourcePermissions": [
{
"projectId": 1,
"resourceType": "NEW_REPORT",
"permissions": ["view"],
"resourceId": 80751
}
],
"filterMap":
{
"47": [
{
"filterType": "listFilter",
"selectType": "select", #如果想要模糊查询,select改成containsList
"database": "supermarket_data",
"tableName": "订单",
"filter": {
"dim":
{
"field": "地区",
"dataType": "String"
},
"select": ["华东"]
}
}
]
}
}
a = get_token(host, post_json)
print(a)
文档反馈
以上内容对您是否有帮助?