0

我设法获得了令牌/令牌秘密,以便向 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"}"

作为答案。我怎么没有身份?

4

1 回答 1

0

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

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

于 2012-07-17T11:55:30.710 回答