对twitter API进行身份验证GET请求

时间:2012-07-16 11:51:01

标签: c++ oauth twitter

我设法获得令牌/令牌秘密,以便向twitter API发出已识别的请求。尽管如此,我还是没有设法使用QOAuth

在C ++中做这样的请求

我正在尝试访问“http://api.twitter.com/1/followers/ids.json”

我使用此代码

_oauthInterface = new QOAuth::Interface(this);
_manager = new QNetworkAccessManager(this);

_oauthInterface->setConsumerKey(CONSUMER_KEY);
_oauthInterface->setConsumerSecret(CONSUMER_SECRET_KEY);

QOAuth::ParamMap params;
    params.insert("user_id", QString::number(id).toAscii());
    params.insert("cursor", cursor.toAscii());

QString url("http://api.twitter.com/1/friends/ids.json");

QByteArray header = _oauthInterface->createParametersString(url,
                                                            QOAuth::GET,
                                                            token.toUtf8(),
                                                            tokenSecret.toUtf8(),
                                                            QOAuth::HMAC_SHA1,
                                                            params,
                                                            QOAuth::ParseForHeaderArguments);

QNetworkRequest request;
if(!params.isEmpty())
    url.append(_oauthInterface->inlineParameters(params, QOAuth::ParseForInlineQuery));

request.setUrl(url);
request.setRawHeader("Authorization", header);

_manager->get(request);

QObject::connect(_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyHandler(QNetworkReply*)));

150请求后我得到了

"{"error":"Rate limit exceeded. Clients may not make more than 150 requests per hour.","request":"\/1\/followers\/ids.json?cursor=-1&user_id=xxxxxxxxx"}"

作为答案。为什么我没被识别?

1 个答案:

答案 0 :(得分:0)

我是多么愚蠢。这段代码很好,我只是用错误的参数(令牌/令牌)而不是(令牌/令牌秘密)调用此函数

请注意,如果访问令牌无效,Twitter不会通知您