创建嵌入链接
本文提供调用「创建嵌入链接」接口的操作示例,请注意该接口仅支持在企业级的空间站中调用。
支持创建嵌入链接的节点类型有:
示例:在维格表中创建嵌入链接
假设你有一个空间站,你想给空间站中的一张表格创建一个嵌入链接。
你的操作步骤如下:
获取你的 API Token。(获取方法)
获取你的空间站 ID。(获取方法)
获取该维格表的 ID(获取方法)
打开你电脑上的终端,执行下列代码,向服务器发送查询请求(假设 spaceId 为
spcjXzqVrjaP3
, nodeId 为dstWUHwzTHd2YQaXEE
)- cURL
- Javascript SDK
- Python SDK
curl -X POST \
"https://vika.cn/fusion/v1/spaces/spcjXzqVrjaP3/nodes/dstWUHwzTHd2YQaXEE/embedlinks" \
-H "Authorization: Bearer {你的 API Token}" \
-H 'Content-Type: application/json' \
-d '{
"payload": {
"primarySideBar": {
"collapsed": false
},
"viewControl": {
"viewId": "viw4mnkqkaqdh",
"tabBar": true,
"nodeInfoBar": false,
"toolBar": {
"basicTools": false,
"widgetBtn": false,
"apiBtn": false,
"formBtn": false,
"historyBtn": false,
"robotBtn": false,
"addWidgetBtn": false,
"fullScreenBtn": false,
"formSettingBtn": false
},
"collapsed": false,
"collaboratorStatusBar": true
},
"bannerLogo": true,
"permissionType": "readOnly"
},
"theme": "light"
}'注意:需要先下载和初始化 Javascript SDK,再执行如下命令。
import { Vika } from '@vikadata/vika';
const vika = new Vika({
token: '你的 API Token',
});
const embedLinkCreateRo = {
"payload": {
"primarySideBar": { "collapsed": false },
"viewControl": {
"viewId": 'viw4mnkqkaqdh',
"tabBar": false,
"nodeInfoBar": false,
"toolBar": {
"basicTools": false,
"widgetBtn": false,
"apiBtn": false,
"formBtn": false,
"historyBtn": false,
"robotBtn": false,
"addWidgetBtn": false,
"fullScreenBtn": false,
"formSettingBtn": false
},
"collapsed": false,
"collaboratorStatusBar": true
},
"bannerLogo": true,
"permissionType": 'readOnly'
},
"theme": EmbedLinkTheme.Light
};
try {
const res = await vika.space('spcjXzqVrjaP3').datasheet('dstWUHwzTHd2YQaXEE').createEmbedLink(embedLinkCreateRo);
if (res.success) {
embedId = res.data?.linkId || '';
}
} catch (error) {
// TODO: handle error
}注意:需要先下载和初始化 Python SDK,再执行如下命令。
from vika import Vika
from vika.types import EmbedLinkThemeEnum, EmbedLinkPermissionType
vika = Vika("你的 API Token")
try:
newEmbedLink = (
vika.space("spcjXzqVrjaP3")
.datasheet("dstWUHwzTHd2YQaXEE")
.create_embed_link(
{
"payload": {
"primarySideBar": {"collapsed": False},
"viewControl": {
"viewId": "viwBBc0PMN3WB",
"tabBar": False,
"toolBar": {
"basicTools": False,
"widgetBtn": False,
"apiBtn": False,
"formBtn": False,
"historyBtn": False,
"robotBtn": False,
"addWidgetBtn": False,
"fullScreenBtn": False,
"formSettingBtn": False
},
"collapsed": False,
"collaboratorStatusBar": True,
"nodeInfoBar": False,
},
"bannerLogo": True,
"permissionType": EmbedLinkPermissionType.READ_ONLY,
},
"theme": EmbedLinkThemeEnum.Light
}
)
)
print(newEmbedLink.linkId)
except Exception:
# 处理异常情况
pass服务器会返回下列 JSON 数据包,嵌入链接的相关信息位于
data
里:{
"code": 200,
"success": true,
"data": {
"linkId": "embb90a52cfc02a4f83",
"url": "https://vika.cn/embed/embb90a52cfc02a4f83",
"payload": {
"primarySideBar": {
"collapsed": false
},
"viewControl": {
"viewId": "viw4mnkqkaqdh",
"tabBar": false,
"toolBar": {
"basicTools": false,
"widgetBtn": false,
"apiBtn": false,
"formBtn": false,
"historyBtn": false,
"robotBtn": false,
"addWidgetBtn": false,
"fullScreenBtn": false,
"formSettingBtn": false
},
"collapsed": false,
"collaboratorStatusBar": true,
"nodeInfoBar": false
},
"bannerLogo": true,
"permissionType": "readOnly"
},
"theme": "light"
},
"message": "SUCCESS"
}提示有关返回结果中各参数的含义,请查看 API 手册。