1
1
#include " oauth.h"
2
2
3
- Oauth::Oauth (QObject *parent) : QObject(parent)
4
- {
5
- /* seed random generator */
6
- qsrand (QTime::currentTime ().msec ());
3
+ Oauth::Oauth (QObject *parent) : QObject(parent) {
4
+ oauthRequest = new KQOAuthRequest;
5
+ oauthManager = new KQOAuthManager;
6
+ oauthRequest->setEnableDebugOutput (true );
7
+ }
8
+
9
+ void Oauth::setSettings (Settings *settings) {
10
+ m_sets = settings;
7
11
}
8
12
9
13
void Oauth::startAuthentication (QString username) {
@@ -31,7 +35,6 @@ void Oauth::startAuthentication(QString username) {
31
35
data.setRequestEndpoint (" http://www.tumblr.com/oauth/request_token" );
32
36
data.setTokenEndpoint (" http://www.tumblr.com/oauth/access_token" );
33
37
34
-
35
38
/* Please read this! ###############
36
39
* these are actually our keys ! if you wish to use this code, please register your key / application at: http://www.tumblr.com/oauth/apps
37
40
*/
@@ -40,9 +43,8 @@ void Oauth::startAuthentication(QString username) {
40
43
// data.setConsumerKey("7zSQ06s60K8PHwXYK1Hw2fTSqgQQkLzPPS14BQQjsXRvQMMWyP");
41
44
// data.setConsumerSecret("8rRNTXMWxe6p5AYumqnZYSDDfofBehF1cjuT05w7nqMHpGy0YZ");
42
45
/* Niwakame's keys */
43
- data.setConsumerKey (" KhJM28EMcP1iEeUomSnFbpwI1YmzPVEYxh1xl07Rlr5AQfbKEj" );
44
- data.setConsumerSecret (" ouPTiEiAU7mUXbkRlDZkD3FlXEAOREWyffmtVuo5bQSanf7UFb" );
45
-
46
+ data.setConsumerKey (m_sets->getConsumerKey ());
47
+ data.setConsumerSecret (m_sets->getConsumerSecret ());
46
48
47
49
data.setCallback (" http://www.tumblr.com/oauth/access_token" );
48
50
data.setDisplayCallback (" true" );
@@ -70,33 +72,62 @@ void Oauth::onResponse(const SignOn::SessionData &sessionData)
70
72
qDebug () << " Access token: " << response.AccessToken ();
71
73
qDebug () << " Toke nSecret: " << response.TokenSecret ();
72
74
75
+ m_sets->setAccessToken (response.AccessToken ());
76
+ m_sets->setAccessTokenSecret (response.TokenSecret ());
73
77
}
74
78
75
79
void Oauth::onApiResponse (QByteArray response) {
76
80
qDebug () << response;
77
81
}
82
+ void Oauth::onApiError (QByteArray response) {
78
83
84
+ }
79
85
80
86
/* test function to get a profile */
81
87
void Oauth::testCall (QString test) {
82
- oauthRequest = new KQOAuthRequest;
83
- oauthManager = new KQOAuthManager;
84
- oauthRequest->setEnableDebugOutput (true );
88
+ oauthRequest->initRequest (KQOAuthRequest::AuthorizedRequest, QUrl (" http://api.tumblr.com/v2/user/info" ));
89
+ // oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl("http://api.tumblr.com/v2/blog/niwakame.tumblr.com/post"));
85
90
86
- // oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl("http://api.tumblr.com/v2/user/info"));
87
- oauthRequest->initRequest (KQOAuthRequest::AuthorizedRequest, QUrl (" http://api.tumblr.com/v2/blog/niwakame.tumblr.com/post" ));
88
- oauthRequest->setConsumerKey (" KhJM28EMcP1iEeUomSnFbpwI1YmzPVEYxh1xl07Rlr5AQfbKEj" );
89
- oauthRequest->setConsumerSecretKey (" ouPTiEiAU7mUXbkRlDZkD3FlXEAOREWyffmtVuo5bQSanf7UFb" );
90
- oauthRequest->setToken (" " );
91
- oauthRequest->setTokenSecret (" " );
92
- oauthRequest->setHttpMethod (KQOAuthRequest::POST);
91
+ oauthRequest->setConsumerKey (m_sets->getConsumerKey ());
92
+ oauthRequest->setConsumerSecretKey (m_sets->getConsumerSecret ());
93
+ oauthRequest->setToken (m_sets->getAccessToken ());
94
+ oauthRequest->setTokenSecret (m_sets->getAccessTokenSecret ());
95
+ // oauthRequest->setHttpMethod(KQOAuthRequest::POST);
93
96
94
- KQOAuthParameters params;
97
+ /* KQOAuthParameters params;
95
98
params.insert("type", "text");
96
99
params.insert("body", "This is a testpost from Meemblr. Fear us :>");
97
- oauthRequest->setAdditionalParameters (params);
100
+ oauthRequest->setAdditionalParameters(params);*/
98
101
99
102
connect (oauthManager, SIGNAL (requestReady (QByteArray)), this , SLOT (onApiResponse (QByteArray)));
100
103
101
104
oauthManager->executeRequest (oauthRequest);
102
105
}
106
+
107
+ void Oauth::callApi (QUrl url, QList< QPair<QString, QString> > params, QString method) {
108
+ oauthRequest->initRequest (KQOAuthRequest::AuthorizedRequest, url);
109
+ oauthRequest->setConsumerKey (m_sets->getConsumerKey ());
110
+ oauthRequest->setConsumerSecretKey (m_sets->getConsumerSecret ());
111
+ oauthRequest->setToken (m_sets->getAccessToken ());
112
+ oauthRequest->setTokenSecret (m_sets->getAccessTokenSecret ());
113
+
114
+ if (method == " POST" ) {
115
+ oauthRequest->setHttpMethod (KQOAuthRequest::POST);
116
+ } else {
117
+ oauthRequest->setHttpMethod (KQOAuthRequest::GET);
118
+ }
119
+
120
+ if (params.size () > 0 ) {
121
+ KQOAuthParameters parameters;
122
+ QPair<QString, QString> pair;
123
+ foreach (pair, params) {
124
+ QString key = pair.first ;
125
+ QString val = pair.second ;
126
+ parameters.insert (key, val);
127
+ }
128
+ oauthRequest->setAdditionalParameters (parameters);
129
+ }
130
+
131
+ connect (oauthManager, SIGNAL (requestReady (QByteArray)), this , SLOT (onApiResponse (QByteArray)));
132
+ oauthManager->executeRequest (oauthRequest);
133
+ }
0 commit comments