From 7e8b64bf8747afb767c5839039e8acf0bf51200c Mon Sep 17 00:00:00 2001 From: Tiago Santos Date: Fri, 14 Aug 2020 16:11:25 +0100 Subject: [PATCH 1/3] Update to ArduinoJson 6 Update to ArduinoJson 6 --- src/TwitterApi.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/TwitterApi.h b/src/TwitterApi.h index 079113b..b889ce4 100644 --- a/src/TwitterApi.h +++ b/src/TwitterApi.h @@ -37,6 +37,8 @@ class TwitterApi String sendGetToTwitter(String command); String getUserStatistics(String screenName); void setBearerToken(String bearerToken); + int getTwitterFollowers(String twitter_name); + bool _debug = false; private: Client *client; From 948ff2683238e297dd4f8815fb2d939754b3571f Mon Sep 17 00:00:00 2001 From: Tiago Santos Date: Fri, 14 Aug 2020 16:12:02 +0100 Subject: [PATCH 2/3] Update TwitterApi.cpp Update to ArduinoJson 6 --- src/TwitterApi.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/TwitterApi.cpp b/src/TwitterApi.cpp index 99b67d8..b9f0132 100644 --- a/src/TwitterApi.cpp +++ b/src/TwitterApi.cpp @@ -96,3 +96,32 @@ String TwitterApi::getUserStatistics(String screenName){ //Serial.println(command); return sendGetToTwitter(command); //recieve reply from twitter } + +int TwitterApi::getTwitterFollowers(String twitter_name){ + String responseString = getUserStatistics(twitter_name); + DynamicJsonDocument jsonBuffer(8096); + DeserializationError error = deserializeJson(jsonBuffer, responseString); + if (_debug){ + switch (error.code()) { + case DeserializationError::Ok: + Serial.print(F("Deserialization succeeded")); + break; + case DeserializationError::InvalidInput: + Serial.print(F("Invalid input!")); + break; + case DeserializationError::NoMemory: + Serial.print(F("Not enough memory")); + break; + default: + Serial.print(F("Deserialization failed")); + break; + } + } + if (!error) { + int twitterFollowers = jsonBuffer["followers_count"].as(); + return twitterFollowers; + } else { + Serial.println("Failed to parse Json for twitter"); + return 0; + } +} From aaa899d9f54c26853840acfb42c2b0070f7f5c24 Mon Sep 17 00:00:00 2001 From: Tiago Santos Date: Fri, 14 Aug 2020 16:12:27 +0100 Subject: [PATCH 3/3] Update to ArduinoJson 6 Update to ArduinoJson 6 --- src/TwitterBearerToken.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TwitterBearerToken.cpp b/src/TwitterBearerToken.cpp index 241cc28..e234184 100644 --- a/src/TwitterBearerToken.cpp +++ b/src/TwitterBearerToken.cpp @@ -112,11 +112,11 @@ String TwitterBearerToken::getNewToken(const char * consumerKey, const char * co } } if (avail) { - DynamicJsonBuffer jsonBuffer; - JsonObject& root = jsonBuffer.parseObject(body); - if (root.success()) { - if (root.containsKey("access_token")) { - token = root["access_token"].as(); + DynamicJsonDocument jsonBuffer(1024); + DeserializationError error = deserializeJson(jsonBuffer, body); + if (!error) { + if (jsonBuffer.containsKey("access_token")) { + token = jsonBuffer["access_token"].as(); return token; } }