oauth, Twitter, and std.net.curl

Taylor Gronka via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 15 07:41:30 PDT 2015


Hello,

I've picked up a web design project, and I would love to use 
vibe.d/dlang. I need to use oauth to search on a number of web 
api's, such as searching for Twitter tweets.

I tried using Adam's oauth (Thanks!). However, it doesn't appear 
support the validation needed for searching Twitter.
https://github.com/adamdruppe/arsd/blob/master/oauth.d


Now I'm looking at std.net.curl, and this is my thought: is 
HTTP.addRequestHeader(key, val) able to set the oauth 
authentication headers? It would look a bit odd, but if something 
like this works, then it wouldn't be difficult to code for each 
set of headers specifically:
	
     auto client = HTTP("https://api.twitter.com"); // not sure if 
https should be set here or somewhere else
     string bearerUrl = "https://api.twitter.com/oauth2/token";
     client.addRequestHeader("Authorization", "Basic 
eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw");
     client.postData("grant_type=client_credentials");
     client.perform();

(The above example is based on Step 2 of this page)
https://dev.twitter.com/oauth/application-only


Of course, the oauth headers look a bit different, but I imagine 
it being something like this:
     client.addRequestHeader("Authorization", "OAuth2 token: 
\"string\", tokensecret: \"string\", appkey, \"string\" ...");
\\ not sure if that's how to escape quotes in dlang


Can I get some guidance on this? I would really like to use 
dlang, but I can't afford to be stuck on this for too long. I'd 
be happy to try and write a modification of Adam's code, but I 
lack experience, so it's a slow process for me.

I'd also be happy to write up little tutorials/blogposts about 
how I accomplish various tasks.

Thanks,





More information about the Digitalmars-d-learn mailing list