前置きもなくいきなりかいつまみます。
QTextStream in(stdin);
QTextStream out(stdout);
QOAuth::Interface qoauth;
qoauth.setConsumerKey("貴様のConsumerKey");
qoauth.setConsumerSecret("貴様のConsumerSecret");
QOAuth::ParamMap reply = qoauth.requestToken( "http://twitter.com/oauth/request_token",
QOAuth::GET,QOAuth::HMAC_SHA1);
QByteArray token;
QByteArray tokenSecret;
if (qoauth.error() == QOAuth::NoError) {
token = reply.value( QOAuth::tokenParameterName() );
tokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
} else return 1;
out << "url: http://twitter.com/oauth/authorize?oauth_token=" << token << endl;
out << "input pin: " << endl;
QString pin;
in >> pin;
QOAuth::ParamMap map;
map.insert("oauth_verifier",pin.toAscii());
reply = qoauth.accessToken("http://twitter.com/oauth/access_token",QOAuth::POST,token,
tokenSecret,QOAuth::HMAC_SHA1,map );
if (qoauth.error() == QOAuth::NoError) {
token = reply.value( QOAuth::tokenParameterName() );
tokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
out << "token: " << token << endl;
out << "tokenSecret: " << tokenSecret << endl;
} else {
qDebug() << qoauth.error();
}
こんな感じ。
requestTimeoutが短いと失敗すると言う罠にずっぽりはまったりとかね。