diff options
author | Caroline Chao <caroline.chao@digia.com> | 2014-10-22 14:59:43 +0200 |
---|---|---|
committer | Caroline Chao <caroline.chao@theqtcompany.com> | 2014-10-23 12:50:02 +0200 |
commit | 17d6a94be624c7ae239087f59e01faf5be558f9f (patch) | |
tree | f5802e48e756dde3c5191cf2b7df7509433a8009 /qml | |
parent | f119b9121a807aca0bfa949cdade2cdc064ef8a8 (diff) |
Twitter reload: request authentication on "bad authentication error"
Currently we only authenticate on Component.onCompleted. When switching
between offline and online mode, authentication is now also possible
to get the tweets.
Change-Id: I760d7178e62c611d33763a444836d22ca1ee26a5
Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'qml')
-rw-r--r-- | qml/components/TweetModel.qml | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/qml/components/TweetModel.qml b/qml/components/TweetModel.qml index e8f295b..f6cad73 100644 --- a/qml/components/TweetModel.qml +++ b/qml/components/TweetModel.qml @@ -58,6 +58,7 @@ Item { signal isLoaded function reload() { + errorMessage = "" tweets.clear() var req = new XMLHttpRequest; @@ -71,7 +72,10 @@ Item { var objectArray = JSON.parse(req.responseText); if (objectArray.errors !== undefined) { console.log("Error fetching tweets: " + objectArray.errors[0].message) - errorMessage = objectArray.errors[0].message + if (objectArray.errors[0].code === 215) // Bad authentication data + authenticate() + else + errorMessage = objectArray.errors[0].message } else { for (var key in objectArray.statuses) { var jsonObject = objectArray.statuses[key]; @@ -89,7 +93,11 @@ Item { req.send(); } - Component.onCompleted: { + Component.onCompleted: authenticate() + + function authenticate() + { + errorMessage = "" var authReq = new XMLHttpRequest; authReq.open("POST", "https://api.twitter.com/oauth2/token"); authReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); |