- Home /
how to post a data to the server ?
Hi, i want to Post a request for getting the access token. how to send the request to Server.
With curl, the request will be similar to:
curl https://api.betable.com/1.0/token \ -u ApI_Key:ApI_Secret \ -d code=code_you_got_back \ -d grant_type=authorization_code \ -d redirect_uri=http://your-redirect-uri/ \ -X POST
here i have Api _Secret,code,redirect url every thing. but by using java script how to write the condition ?
what is this curl method ?
Thank you,
Answer by Logistic Win Software · Aug 21, 2013 at 04:05 AM
Can I get your assistance with integrating Betable in a Unity Project? This is a HUGE deal for me and I need some help.
Answer by whydoidoit · May 30, 2012 at 11:27 AM
Best thing to do is look at this documentation for WWWForm http://unity3d.com/support/documentation/ScriptReference/WWWForm.html
Thanks for ur reply. i want to solve this Step-4. Step 4: Exchange the code for an access token
The code we sent you back in step 3 can be redeemed for a user access token. Just like at an arcade.
This time you should make a secure server-side call, which will include your client_secret, so we’re sure the request comes from you. You should use HTTP Basic Authentication in this call, using your API $$anonymous$$EY as username and your API SECRET as password.
The URI to send the request to will look like this:
POST https://api.betable.com/1.0/token The body of the request will need the following parameters, url-encoded:
grant_type=authorization_code redirect_uri=YOUR_REDIRECT_URI code=CODE_YOU_GOT_ON_STEP_3 Parameter Required Description redirect_uri Yes This must be the same value as what you defined in the developer dashboard. We won't do anything with it at this time, but this is required for security reasons by the OAuth spec. code Yes This is the code that you got back in Step 3. Without this we would not know what user you want an access_token for, so it's pretty important.' grant_type Yes This must be set to authorization_code, as required by the OAuth spec. With curl, the request will be similar to:
curl https://api.betable.com/1.0/token \ -u ApI_$$anonymous$$ey:ApI_Secret \ -d code=code_you_got_back \ -d grant_type=authorization_code \ -d redirect_uri=http://your-redirect-uri/ \ -X POST In Ruby, the call will look like this:
url = URI.parse('https://api.betable.com/1.0/token') req = Net::HTTP::Post.new(url.path) req.set_form_data( { :grant_type => 'authorization_code', :code => params[:code], :redirect_uri => "http://localhost:4567/callback" }) req.basic_auth 'ApI_$$anonymous$$ey', 'ApI_SecRet' http = Net::HTTP.new(url.host, url.port) http.use_ssl = true response = http.request(req) You should then parse the response that you will get from Betable. The body of the response will be a url-encoded string that will include the final access_token.
access_token=USER_ACESS_TO$$anonymous$$EN&token_type=Bearer This access_token will enable you to make bet requests on behalf of the user, so you should be persisting the token in order to make requests even after the user’s first visit.
For security reasons, our tokens expire after a period of time. At that point, you should re-initiate the flow from step 1. If the user has not deauthorized your app in the meantime, he will not be shown the authorization request and we will automatically send you a new code that you can exchange for a new access_token.
If there is a problem validating the code or creating an access_token, we will issue an HTTP 400 error and return a response with JSON in the body explaining what went wrong. It could look like this:
{ "error": { "type": "OAuthException", "message": "Validation of the code failed." } }
Yeah OAuth is a pig :) I've done if from web sites, but I use www.Prime31.com to do my social integration from the device.
Answer by ina · Jul 21, 2013 at 02:02 AM
curl params via Unity WWWForm
WWWForm.headers should help with the basic auth.
this is just WWWForm data
Your answer
Follow this Question
Related Questions
unity + amf 0 Answers
Unity networking tutorial? 6 Answers
Can't Send a form to a server(POST) due to CORS error in a WEBGL build 1 Answer