ThingTweet App
使用 ThingTweet App 将 Twitter® 帐户链接到您的 ThingSpeak™ 帐户。设备和通道可以使用 TweetControl API 通过 Twitter 进行更新。示例,当温室温度下降或设备电池电量不足时,您可以让设备向您发送推文。
将 Twitter 帐户与 ThingSpeak 帐户关联
如果您登录 Twitter 帐户,ThingTweet 会自动将可用的 Twitter 帐户与您的 ThingSpeak 用户帐户关联。注销 Twitter 以关联其他帐户。
Sign In 至 ThingSpeak。
选择Apps > ThingTweet。
点击 Link Twitter Account。
您将被重定向至 Twitter。当要求授权 ThingTweet 使用您的帐户时:
输入您的 Twitter 用户名和密码。
点击 Authorize app。
确认 Twitter 帐户后,点击链接 Back to ThingTweet 返回 ThingTweet App 页面。
请注意,您的 Twitter 帐户现已链接到 ThingSpeak
该 App 会生成一个 ThingTweet API 密钥供您使用。使用此 API 密钥和消息向 ThingTweet 发送请求。该消息被转发到 Twitter。您可以使用Twitter API的所有参数来发送消息。有关详细信息,请参阅 Twitter 文档中的 statuses / update。要查看每个 ThingTweet App 的 ThingTweet API 密钥,请选择Apps > ThingTweet。
更新 Twitter 状态
要使用 ThingTweet 更新您的 Twitter 状态,请使用 ThingTweet API 密钥和您的状态消息发送 HTTP POST 或 GET。
标题 | 更新 Twitter 状态的 HTTP 请求 |
---|---|
网址 | https://api.thingspeak.com/apps/thingtweet/1/statuses/update |
HTTP Method | 发布或获取 |
POST HTTP 标头 | X-THINGSPEAKAPIKEY=XXXXXXXXXXXXXXX |
数据参数 | api_key=XXXXXXXXXXXXXXXstatus=I just posted this from my Thing at %%datetime%% |
成功响应 | 1 |
错误响应 | –1 |
示例 POST HTTP 调用 | POST /apps/thingtweet/1/statuses/update HTTP/1.1 Host: api.thingspeak.com Content-Type: application/x-www-form-urlencoded Cache-Control: no-cacheapi_key=YOUR_THINGTWEET_API_KEYstatus=I+just+posted+this+from+my+Thing+at+%25%25datetime%25%25 |
示例 GET HTTP 调用 | https://api.thingspeak.com/apps/thingtweet/1/statuses/update?api_key=XXXXXXXXXXXXXXXX&status=HeyWorld |
注释 | ThingTweet API 密钥必须出现在 HTTP头文件或 POST 的主体部分中,或者可以同时出现在两者中 |
POSTMAN 请求示例
您可以使用 POSTMAN 使用 ThingSpeak 的 RESTful API 来尝试 HTTP 请求。选择请求的 Body 作为 x-www-form-urlencoded。通过配置 POSTMAN 来测试 tweet请求,如图所示。
使用通道中的最后值更新 Twitter 状态
您可以在 Twitter 消息中包含通道数据。ThingTweet 将 "%%channel_CHANNEL-ID_field_FIELD-NUMBER%%"
替换为指定通道和字段的最后一个值。要使用通道 1417 field1
的最新值更新 Twitter 状态,请发送 HTTP POST。
标题 | HTTP POST 请求使用通道字段中的最后值更新 Twitter 状态 |
---|---|
网址 | https://api.thingspeak.com/apps/thingtweet/1/statuses/update |
HTTP Method | POST |
HTTP Header | X-THINGSPEAKAPIKEY=XXXXXXXXXXXXXXX |
数据参数 | api_key=XXXXXXXXXXXXXXXXstatus=The current CheerLights color is %%channel_1417_field_1%% at %%datetime%% |
成功响应 | 1 |
错误响应 | –1 |
示例 HTTP 调用 | POST /apps/thingtweet/1/statuses/updateHTTP/1.1 Host: api.thingspeak.com Content-Type: application/x-www-form-urlencoded Cache-Control: no-cacheapi_key=YOUR_THINGTWEET_API_KEYstatus=The+current+CheerLights+color+is+%25%25channel_1417_field_1%25%25+at+%25%25datetime%25%25 |
注释 | ThingTweet API 密钥必须出现在 HTTP头文件或主体部分中,或者可以同时出现在两者中 |
POSTMAN 请求示例
您可以使用 POSTMAN 使用 ThingSpeak 的 RESTful API 来尝试 HTTP 请求。使用 POSTMAN 测试 tweet请求并按所示进行配置。
要更新通道并同时从您的设备发布推文,请参阅 Write Data。
更换密钥
您可以使用替换密钥将数据传递到您的 App 。下表总结了您可以使用的标准和自定义替换密钥。某些键特定于特定类型的请求,如最后一列所示。
键 | 描述 | 例子 | 使用场合 |
---|---|---|---|
%%YOUR_CUSTOM_LABEL%% | ThingHTTP 将此自定义替换值替换为触发请求中具有标签“YOUR_CUSTOM_LABEL”的数据。 | field1=%%YOUR_CUSTOM_LABEL%% POST 数据:YOUR_CUSTOM_LABEL=1234 .结果:field1=1234 。 | 任何请求 |
%%channel_CHANNEL_ID_field_FIELD_NUMBER%% | 指定通道和字段的最后一个值。对与 ThingHTTP请求不属于同一用户的私有通道的替换请求将返回空白值。 | The latest value is %%channel_12_field_1%% .结果:The latest value is 2.5 . | 任何请求 |
%%datetime%% | TimeControl 或 React 运行时的完整日期和时间。 | The date and time the event occurred is %%日期时间%% .结果:The date and time the event occurred is 2014-09-24 5:32 pm . | 时间控制或反应 |
%%day%% | TimeControl 运行时的工作日名称。 | The day the event occurred is %%day%% .结果:The day the event occurred is 星期三。 | TimeControl |
%%day_index%% | 从星期日开始的工作日的从零开始的索引。 | The number of days used this week is %%day_index%% .结果:The number of days used this week is 3 . | TimeControl |
%%hour%% | TimeControl 运行的时间。 | The hour that the event occurred is %%小时%% .结果:The hour that the event occurred is 5 . | TimeControl |
%%minute%% | TimeControl 运行时的分钟。 | The minute the event occurred is %%分钟%% .结果:The minute the event occurred is 30 . | TimeControl |
%%trigger%% | 触发 React 的值。 | It is way too hot in here at %%trigger%% C .结果:It is way too hot in here at 40 C 。 | 反应 |
%%channel_id%% | 触发React的通道ID。 | The channel that tweets is %%channel_id%% .结果:The channel that tweets is 1256 。 | 反应 |