阅读(2464) (0)

百度智能小程序 获取第三方自定义数据字段

2020-08-13 16:23:30 更新

swan.getExtConfig

基础库 1.10.8 版本开始支持,需要上传小程序包之后,才能通过 API 获取自定义数据,小程序包上传流程、数据。

解释:获取第三方平台自定义的数据字段。

方法参数

Object object

object参数说明

属性名类型必填默认值说明

success

Function

返回第三方平台自定义的数据

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明

参数类型说明

extConfig

Object

第三方平台自定义的数据

示例 

在开发者工具中打开


图片示例

代码示例

<view class="wrap">
    <view class="card-area">
        <view class="top-description border-bottom">获取第三方平台自定义的数据字段</view>
        <button bindtap="getExtConfig" type="primary" hover-stop-propagation="true">点击获取</button>
    </view>
</view>

Page({
    getExtConfig() {
        swan.getExtConfig({
            success: res => {
                console.log('自定义的数据', res.extConfig);
                swan.showToast({
                    title: 'api调用成功,但需请求携带三方数据的server接口',
                    icon: 'none'
                });
            },
            fail: err => {
                console.log('getExtConfig fail', err);
                swan.showToast({
                    title: '获取失败',
                    icon: 'none'
                });
            }
        });
    }
});

Bug & Tip

  • swan.getExtConfig 暂时无法通过 sawn.canIUse 判断是否兼容,开发者需要自行判断 swan.getExtConfig 是否存在兼容。
  • 需要小程序授权第三方平台,并且添加自定义字段值(例:{"extEnable":true,"ext":{"appid":"xxx"}}),swan.getExtConfig()方法请求的时候返回的 extConfig 值才不为{}。