Skip to content

Commit

Permalink
Update demo for Qt 6.
Browse files Browse the repository at this point in the history
  • Loading branch information
pipacs committed Dec 29, 2021
1 parent 8492f54 commit e562613
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 9 additions & 1 deletion examples/sialis/README.md
@@ -1,5 +1,13 @@
# Sialis

Twitter demo for O2, demonstrating authenticating with Twitter and signing requests in order to show tweets.
GUI demo for O2, demonstrating using O2 from QML, authenticating with Twitter and sending signed requests in order to show some tweets.

To try out Sialis:

1. Login to developer.twitter.com with your Twitter credentials
1. Create a new application "Sialis", record its API Key and API Secret
* Enable OAuth 1.0a authentication
* Set the callback URI to _http://127.0.0.1:8888/_
1. In _main.qml_, change the O1Twitter object's _clientId_ property to the application's API Key
1. Change the _clientSecret_ property to the application's API secret
1. Build and run, press the _Login_ button to log in to Twitter and show the latest tweets
15 changes: 8 additions & 7 deletions examples/sialis/main.qml
@@ -1,7 +1,7 @@
import QtQuick 2.3
import QtQuick.Controls 1.4
import QtWebView 1.1
import com.pipacs.o2 1.0
import QtQuick
import QtQuick.Controls
import QtWebView
import com.pipacs.o2

ApplicationWindow {
id: app
Expand All @@ -13,8 +13,9 @@ ApplicationWindow {

O1Twitter {
id: o1Twitter
clientId: "2vHeyIxjywIadjEhvbDpg"
clientSecret: "Xfwe195Kp3ZpcCKgkYs7RKfugTm8EfpLkQvsKfX2vvs"
clientId: "The app's API Key from developer.twitter.com"
clientSecret: "The app's API Secret from developer.twitter.com "
localPort: 8888

onOpenBrowser: {
browser.url = url
Expand All @@ -36,7 +37,7 @@ ApplicationWindow {
authenticator: o1Twitter
}

statusBar: StatusBar {
footer: ToolBar {
Label {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
Expand Down
10 changes: 7 additions & 3 deletions src/o1.cpp
Expand Up @@ -30,7 +30,7 @@ O1::O1(QObject *parent, QNetworkAccessManager *manager, O0AbstractStore *store):
setSignatureMethod(O2_SIGNATURE_TYPE_HMAC_SHA1);
manager_ = manager ? manager : new QNetworkAccessManager(this);
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");

setCallbackUrl(O2_CALLBACK_URL);
}

Expand Down Expand Up @@ -233,13 +233,13 @@ void O1::link() {
setToken("");
setTokenSecret("");
setExtraTokens(QVariantMap());

if (!useExternalWebInterceptor_) {
// Start reply server
if (!replyServer()->isListening())
replyServer()->listen(QHostAddress::Any, localPort());
}

// Get any query parameters for the request
#if QT_VERSION >= 0x050000
QUrlQuery requestData;
Expand Down Expand Up @@ -274,6 +274,10 @@ void O1::link() {
headers.append(O0RequestParameter(O2_OAUTH_VERSION, "1.0"));
headers.append(O0RequestParameter(O2_OAUTH_SIGNATURE_METHOD, signatureMethod().toLatin1()));
headers.append(O0RequestParameter(O2_OAUTH_SIGNATURE, generateSignature(headers, request, requestParameters(), QNetworkAccessManager::PostOperation)));
qDebug() << "O1:link: Token request headers:";
foreach(param, headers) {
qDebug() << " " << param.name << "=" << param.value;
}

// Clear request token
requestToken_.clear();
Expand Down

0 comments on commit e562613

Please sign in to comment.