安装SDK
更新时间:2020-04-10
Node.js环境
支持的Node.js版本
Node 4.x 以及更高版本
安装步骤
- 推荐使用 npm 来安装:
Plain Text
1npm install @baiducloud/sdk
- 然后在你的程序中使用:
Plain Text
1const Client = require('@baiducloud/sdk').BtsClient;
2
3const config = {
4 endpoint: <EndPoint>, //您选择的EndPoint
5 credentials: {
6 ak: <AccessKeyID>, //您的AK
7 sk: <SecretAccessKey> //您的SK
8 }
9};
10
11let myClient = new Client.BtsClient(config);
12
13myClient.listInstances()
14 .then(response => console.log(response)) // 成功
15 .catch(error => console.error(error)); // 失败
接口会返回一个promise对象。
浏览器环境
支持的浏览器版本:
浏览器类型 | 最低版本 |
---|---|
Google Chrome | 28.0+ |
Microsoft Internet Explorer | 10.0+ |
Mozilla Firefox | 23.0+ |
Apple Safari | 5.1+ |
Opera | 17.0+ |
Android Browser | 4.3+ |
安装步骤
- 推荐使用 npm 来安装:
Plain Text
1npm install @baiducloud/sdk
- 加载 baidubce-sdk.bundle.min.js到页面:
Plain Text
1<script src="node_modules/@baiducloud/sdk/dist/baidubce-sdk.bundle.min.js"></script>
当 js 加载到页面之后,可以用过全局变量 baidubce.sdk来使用 sdk 的功能。
- 然后在你的程序中使用:
Plain Text
1const config = {
2 endpoint: <EndPoint>, //您选择的EndPoint
3 credentials: {
4 ak: <AccessKeyID>, //您的AK
5 sk: <SecretAccessKey> //您的SK
6 }
7};
8
9
10let myClient = new baidubce.sdk.BtsClient.BtsClient(config);
11
12myClient.listInstances()
13 .then(response => console.log(response)) // 成功
14 .catch(error => console.error(error)); // 失败