0

This is request

 POST /oauth/token HTTP/1.1
 Host: api.quizlet.com
 Authorization: Basic N0pIMzhUMjd6TTpOM3JYd3l2TU5OWlNGQWNBd0ozZ3lH
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
 grant_type=authorization_code&code=GENERATED_CODE

This is response

{
    "access_token": "46a54395f3d1108feca56c7f6ca8dd3d",
    "token_type": "bearer",
    "expires_in": 3600,
    "scope": "read",
    "user_id": "ryu_nishida"
}

This is my code

 Unirest.post "http://api.quizlet.com/oauth/token", 
 headers:{ Authorization: "Basic 
 N0pIMzhUMjd6TTpOM3JYd3l2TU5OWlNGQWNBd0ozZ3lH"}, 
 grant_type=authorization_code&code=GENERATED_CODE

There are no responses from my code but it doesn't exist any errors.

matt
  • 78,533
  • 8
  • 163
  • 197

1 Answers1

2

You need to save the response object in a variable,

response = Unirest.post("http://api.quizlet.com/oauth/token",
             auth:{:user=>"username", :password=>"password"})

Then you have methods to get details

response.code # Status code
response.headers # Response headers
response.body # Parsed body
response.raw_body # Unparsed body

Read the docs

Md. Farhan Memon
  • 6,055
  • 2
  • 11
  • 36
  • I read docs but I couldn't understand where I should write grant_type. – Ryu Nishida Jun 03 '17 at 11:44
  • It happened a error SyntaxError in WordsController#new /Users/nishidaryu/RubymineProjects/share- tan/app/controllers/words_controller.rb:190: syntax error, unexpected ')', expecting => – Ryu Nishida Jun 03 '17 at 11:54