Problem with authorizing a request / qt 5.5 / c++


#1

I’m trying to post a status using the information given on api documentation . I get the data from outh tool to make sure it is correctly calculated and then I copy them to my code to test if I can send a request succesfully.
Here is an example of what I get when I send the same request to another server:

Total-Route-Time: 0
Content-Length: 76
Via: 1.1 vegur
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Host: requestb.in
Connection: close
X-Imforwards: 20
Connect-Time: 1
User-Agent: Mozilla/5.0
Accept: */*
X-Request-Id: b85f8651-487f-4b67-a9ff-cd50f75b2d20
Accept-Language: tr-TR,en,*
Authorization: OAuth oauth_consumer_key="xxx",oauth_nonce="44eb1361a122ddf27e3e8b161a9ad47e",oauth_signature="DX5bD3FvGuGqceH6894Z2MV1A3c%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1440485114",oauth_token="xxx",oauth_version="1.0"

data: status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21

So it looks pretty similar to the one that is given on this site but when I try to send this request to api.twitter I have an error which is {“errors”:[{“message”:“Could not authenticate you”,“code”:32}]}.

For the coding part I tried to use o2 library but learned that its twitter example is old now and by using the request code from it I come up with a simpler code like this to send tweets:

QNetworkAccessManager* manager = new QNetworkAccessManager(this);
QByteArray postData = "status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21";
QUrl url = QUrl("https://api.twitter.com/1.1/statuses/update.json");
QList<O1RequestParameter> oauthParams;
    oauthParams.append(O1RequestParameter(O2_OAUTH_CONSUMER_KEY, "xxx"));
    oauthParams.append(O1RequestParameter(O2_OAUTH_VERSION, "1.0"));
...//all parameters for header are entered and alphabetically ordered
QNetworkRequest request(url);
    request.setRawHeader(O2_HTTP_AUTHORIZATION_HEADER, buildAuthorizationHeader(oauthParams));
    request.setHeader(QNetworkRequest::ContentTypeHeader, O2_MIME_TYPE_XFORM);
    manager->post(request, postData);

Finally problem is as I mentioned; I cannot send send tweets by authorizing a request.(signature I use is correct since I get it direct from the oauth tool) pls help


#2

I still couldn’t solve the problem but after a try I found out that I can use GET methods succesfully . Also I built another program that uses pin authentication and it works for the first two steps which are getting pin and using that pin to get access token and secret but at the last step which is sending atweet with the provided access token and secret I’m having the same problem as above.

tl;dr : still not working but interestingly post methods of first 2 steps of pin authentication and get methods work without any problem. pls help

Also an example with qt(c++) would be great :slight_smile: