#2 should work, the problem right now is that we only have support for json encoded data, and so the post method is overriding "Content-Type" (https://github.com/loladiro/Requests.jl/blob/master/src/Requests.jl#L269).
I've just filed https://github.com/loladiro/Requests.jl/issues/15 to track On Wednesday, February 5, 2014 1:11:11 PM UTC-8, Bassem Youssef wrote: > > Hi Randy, > The following works for me: > where $enc is the encoded creds as you had above. > > post(URI("https://api.twitter.com/oauth2/token"),"grant_type=client_credentials",{"Authorization" > > => "Basic $enc","Content-Type" => > "application/x-www-form-urlencoded;charset=UTF-8"}) > > Note the URI() before the url. We should fix that. > > regards, > Bassem > > > On Wed, Feb 5, 2014 at 9:18 AM, Randy Zwitch > <[email protected]<javascript:> > > wrote: > >> I'm trying to work through the application-only authentication for >> Twitter (https://dev.twitter.com/docs/auth/application-only-auth), but I >> can't seem to get the POST request right at step 2. >> >> I'm fairly certain I have the credentials portion right, but for whatever >> reason I can't get Twitter to recognize the body of my request. Here's what >> I've tried: >> >> using Codecs, HttpCommon, Requests >> >> consumer_key = "6nOtpXmf4bYuu3..."; >> consumer_secret = "sES5Zlj096St0O65VX..."; >> >> #Function to create authentication header >> function encodecredentials(consumer_key::String, consumer_secret::String) >> #URI encode keys for future-proofing, per Twitter docs >> bearer_token_credentials = >> "$(encodeURI(consumer_key)):$(encodeURI(consumer_secret))" >> return(base64(bearer_token_credentials)) >> end >> >> #1. Try POST request by itself - Expect an error >> >> response = post("https://api.twitter.com/oauth2/token") >> println(response.data) >> >> {"errors":[{"label":"authenticity_token_error","code":99,"message":"Unable >> to verify your credentials"}]} >> >> #2. Add in authentication >> #Change in error message suggests Twitter okay with my Authorization >> credentials >> >> response = post("https://api.twitter.com/oauth2/token"; >> headers = {"Authorization" => "Basic >> $(encodecredentials(consumer_key, consumer_secret))", >> "Content-Type" => >> "application/x-www-form-urlencoded;charset=UTF-8"}, >> data = "grant_type=client_credentials") >> println(response.data) >> >> {"errors":[{"label":"forbidden_missing_parameter","code":170,"message":"Missing >> required parameter: grant_type"}]} >> >> >> #3. Try authentication with data as Dict instead of string >> >> #Get same error message >> >> >> response = post("https://api.twitter.com/oauth2/token"; >> headers = {"Authorization" => "Basic >> $(encodecredentials(consumer_key, consumer_secret))", >> "Content-Type" => >> "application/x-www-form-urlencoded;charset=UTF-8"}, >> data = {"grant_type" => "client_credentials"}) >> println(response.data) >> >> >> {"errors":[{"label":"forbidden_missing_parameter","code":170,"message":"Missing >> required parameter: grant_type"}]} >> >> >> So regardless of how I specify the body parameter, Twitter doesn't want >> to recognize what I'm doing. Is there a different way I'm supposed to add >> data to a POST request? >> > >
