Skip to content

Commit 42be954

Browse files
committed
Example review tweaks
1 parent b5d9ba5 commit 42be954

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

examples/GetTwitterStatus/GetTwitterStatus.ino

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
22
Get twitter status
33
4-
This example shows a REST API GET using OAuth
4+
This example shows a REST API GET using OAuth
55
authentication. It then parses the JSON response.
66
7-
OAuth credentials can be retrieved from your Twitter
7+
OAuth credentials can be retrieved from your Twitter
88
developer account after creating a new app:
99
1010
https://developer.twitter.com/en/apps
1111
1212
Circuit:
13-
13+
1414
- Arduino MKR WiFi 1010 board
1515
1616
This example code is in the public domain.
@@ -20,8 +20,8 @@
2020
#include <ArduinoBearSSL.h> // Arduino_OAuth depends on ArduinoBearSSL
2121
#include <ArduinoHttpClient.h> // Arduino_OAuth depends on ArduinoHttpClient
2222
#include <Arduino_OAuth.h>
23+
#include <Arduino_JSON.h>
2324
#include <WiFiNINA.h>
24-
#include <JSON.h>
2525

2626
#include "arduino_secrets.h"
2727
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
@@ -38,6 +38,8 @@ int status = WL_IDLE_STATUS; // the Wifi radio's status
3838
WiFiSSLClient wifiSSLClient;
3939
OAuthClient oauthClient(wifiSSLClient, "api.twitter.com", 443);
4040

41+
String twitterHandle = "arduino"; // Twitter handle to retrieve Tweets from
42+
4143
void setup() {
4244
//Initialize serial and wait for port to open:
4345
Serial.begin(9600);
@@ -91,7 +93,7 @@ unsigned long getTime() {
9193

9294
void loop() {
9395
// Twitter API requests latest Arduino status
94-
oauthClient.get("/1.1/statuses/user_timeline.json?screen_name=arduino&count=1");
96+
oauthClient.get("/1.1/statuses/user_timeline.json?screen_name=" + twitterHandle + "&count=1");
9597

9698
int statusCode = oauthClient.responseStatusCode();
9799
String response = oauthClient.responseBody();
@@ -100,21 +102,24 @@ void loop() {
100102
// An error occurred
101103
Serial.println(statusCode);
102104
Serial.println(response);
103-
}
104-
105-
else
106-
107-
{
105+
} else {
108106
// Parse JSON response
109107
JSONVar statusesObject = JSON.parse(response);
110-
Serial.println("");
111-
Serial.println("@arduino twitter status: ");
108+
109+
// print the handle
110+
Serial.print("@");
111+
Serial.print(twitterHandle);
112+
Serial.println("'s twitter status: ");
113+
114+
// print the tweet text, retweet + favorite counts
115+
// we only care about the first item
112116
Serial.println(statusesObject[0]["text"]);
113-
Serial.print("Retweeted: ");
117+
Serial.print("Retweets: ");
114118
Serial.println(statusesObject[0]["retweet_count"]);
115-
Serial.print("Favorited: ");
119+
Serial.print("Likes: ");
116120
Serial.println(statusesObject[0]["favorite_count"]);
117121
}
122+
Serial.println();
118123

119124
// Wait one minute (see Twitter API rate limits before changing)
120125
delay(60 * 1000L);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_PASS ""
3+
4+
// from https://developer.twitter.com/en/apps
5+
#define SECRET_CONSUMER_KEY ""
6+
#define SECRET_CONSUMER_KEY_SECRET ""
7+
#define SECRET_ACCESS_TOKEN ""
8+
#define SECRET_ACCESS_TOKEN_SECRET ""

0 commit comments

Comments
 (0)