开发者

Signing twitter user stream request with OAuth

I'm trying to sign a request with OAuth. I read a lot of articles on it, but I don't know how to actually use it right now.

I have this URL: https://userstream.twitter.com/2/user.json And I want to call it for a certain user. I have an app (with Consumer key en secret) and the API key for the account I want to use. So the only thing left to do is sign it. I used this page: http://hueniverse.com/2008/10/beginners-guide-to-oauth-part-iv-signing-requests/ and got a code block that looked like this one:

GET /photos?size=original&file=vacation.jpg HTTP/1.1
Host: photos.example.net:80
Authorization: OAuth realm="http://photos.example.net/photos",
    oauth_consumer_key="dpf43f3p2l4k3l03",
    oauth_token="nnch734d00sl2jdk",
    oauth_nonce="kllo9940pd9333jh",
    oauth_timestamp="1191242096",
    oauth_signature_method="HMAC-SHA1",
    oauth_version="1.0",
    oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"

However, cURL does not accept that. How do I construct something that will work w开发者_如何学运维ith cURL?

Thanks in advance

EDIT: I don't really need cURL, just comething that I can use with C++ on GNU/Linux


When I've curled a Twitter request from the (Windows) command line, and had to add an OAuth authorization header, I've done it like this:

curl -k "https://userstream.twitter.com/2/user.json" --header "Authorization: OAuth realm=""Twitter API"",oauth_consumer_key=""dpf43f3p2l4k3l03"",oauth_token=""nnch734d00sl2jdk"",oauth_nonce=""kllo9940pd9333jh"",oauth_timestamp=""1191242096"",oauth_signature_method=""HMAC-SHA1"",oauth_version=""1.0"",oauth_signature=""tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"""

Of course, if you're using that Java applet, be sure you've set the time as close to the correct time as possible, specified your OAuth credentials, and set the URL part appropriately before substituting the output values into the command line above.

Method: GET
URI Scheme: https
Host Name: userstream.twitter.com
Port: 443
Request Path: /2/user.json
Parameters: [remove all]

Note in the header output that you must manually change the realm to Twitter API, but all the other output values should be correct.

Additionally, this answer has a good selection of C++ Twitter libraries you could try, although the link to the Twitter documentation that lists is out of date -- here's the latest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜