{"id":13338662,"url":"https://github.com/TuyaInc/tuya_cloud_sdk_nodejs","last_synced_at":"2025-03-11T10:31:40.735Z","repository":{"id":105374260,"uuid":"258122124","full_name":"TuyaInc/tuya_cloud_sdk_nodejs","owner":"TuyaInc","description":"Cloud API SDK for node.js","archived":false,"fork":false,"pushed_at":"2020-09-27T11:39:24.000Z","size":34,"stargazers_count":0,"open_issues_count":2,"forks_count":2,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-23T22:18:03.028Z","etag":null,"topics":["tuya"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TuyaInc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-23T07:04:14.000Z","updated_at":"2021-08-05T13:44:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7933c96-c032-4996-9482-3c91f5e9f820","html_url":"https://github.com/TuyaInc/tuya_cloud_sdk_nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuyaInc%2Ftuya_cloud_sdk_nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuyaInc%2Ftuya_cloud_sdk_nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuyaInc%2Ftuya_cloud_sdk_nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuyaInc%2Ftuya_cloud_sdk_nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TuyaInc","download_url":"https://codeload.github.com/TuyaInc/tuya_cloud_sdk_nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243015416,"owners_count":20222078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tuya"],"created_at":"2024-07-29T19:17:03.146Z","updated_at":"2025-03-11T10:31:40.728Z","avatar_url":"https://github.com/TuyaInc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 涂鸦云云对接API SDK Nodejs版本\n\n## 使用前需要做\n1. 确认nodejs版本在7.10.1及以上\n\n2. 在涂鸦云平台注册开发者账号，确定`AccessID、AccessKey、Endpoint`(调用地址)这些值\n\n## 源码安装\n1. 解压源码包到您项目合适的位置。\n2. 代码中引用对应模块代码，可参考示例。\n\n## Example\n\n在你运行本sdk前，显式初始化一次开发者信息：\n```\n   Config.init(accessID, accessKey, Region.URL_CN);\n```\n\n以获取设备信息接口为例，直接调用device.GetDevice()即可:   \n```nodejs\n    \n    let deviceId = 'xxxx';\n    let callback = function(err, data) {\n        if (err) {\n            console.log(err);\n            return;\n        }\n    \n        console.log(data);\n    };\n    \n    // 获取设备信息\n    DeviceClient.getDevice(deviceId, callback);\n    \n```\n\n## 目前支持的API\n\n|  模块                   | 请求类 |\n|  ----                     |  ----  |\n| token相关 | TokenClient |\n| 用户管理 | UserClient | \n| 设备管理 | DeviceClient |\n| 设备控制 | DeviceControlClient |\n| 设备群组 | DeviceGroupClient |\n| 设备成员管理| DeviceMemberClient |\n| 数据统计 | DataClient | \n| 家庭管理 | HomeClient | \n| 自动化 | AutomationClient | \n| 场景 | SceneClient | \n| 配网管理 | PairTokenClient | \n| 定时管理 | TimeClient | \n| 天气管理 | WeatherClient |\n\n## 常见问题\n\n### 关于refreshToken接口\n\n注意： refreshToken接口会返回一个新的access_token，即使旧的token还未过期。\n\n这个逻辑在GetToken方法中已经做了，用户一般不需要调用refresh接口。\n\n### 每次调用api之前，是否需要获取token或者刷新token？\n\n不需要，这层逻辑已经在api方法中实现了。token信息会缓存到内存中。\n\n### 调用某个接口时，如果token已经过期，需要手动调用refresh-token接口？\n\n不需要，在GetToken()方法实现中，会检查token是否过期。如果过期会去重新拉取。\n\n### 如果你的token会在多个节点中去刷新，那么你需要自己实现common.TokenLocalManage interface\n涂鸦的云token，只保证面向的用户级别刷新不会有问题，但是一个用户的token在多个节点并发刷新，就会导致一个节点是成功的，\n其他都是失败；\n因为 `获取token`接口会返回一个access_token、refresh_token，但是 `刷新token`接口 会把当前的refresh_token 刷掉，会产生一个新的，旧的失效；\n\n### api方法的异常信息和error需要如何处理？\n\n接口如果返回error，一般可以为url错误或者json解析出错，可联系涂鸦相关人员帮忙修改\n\n如果error为空，但是response的success字段为false，开发者可以根据Msg字段的详细错误信息进行排查\n\n### 获取设备列表接口，如果多个deviceID，需要怎么拼接？\n\n多个deviceID，以英文逗号分割拼接\n\n### 获取用户列表接口中，schema指的是什么？\n\n创建APP-SDK后，详情页面的渠道标识符就是schema\n\n### v1.0/devices/tokens/{{pair_token}}接口，pair_token是指什么？如何获取？\n\npair_token是指app下的某个用户的配网token，可以从v1.0/devices/token获取。\n\n### 如果SDK中的API没有及时更新，如何自己实现一个API？\n\n有三种方法：\n\n一、自定义类实现\n1. 如果请求不需要传递body参数，通过创建请求类继承com.tuya.api.common.ApiRequest, 并完善其中getRequestMethod和getRequestUrl两个方法即可，\n如果接口需要传递body参数，应继承com.tuya.api.common.ApiRequestBody, 完善getRequestMethod、getRequestUrl和getRequestBody方法；\n\n2. 通过client类暴露请求方法。\n\n\u003e 具体可以参考example.user/example.device目录下相关示例;\n\n二、使用提供的通用接口\n直接调用CommonClient, 传入相应的参数即可。\n\n\u003e 具体可以参考example.common目录下相关示例;\n\n三、提个issue，我们会及时更新 ^_^\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTuyaInc%2Ftuya_cloud_sdk_nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTuyaInc%2Ftuya_cloud_sdk_nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTuyaInc%2Ftuya_cloud_sdk_nodejs/lists"}