我收到以下代码:
{"data":{"error":"Invalid grant_type parameter or parameter missing","request":"\/oauth2\/token","method":"Post"}
public class Authentication_Token {
private String Client_ID = "9d99755c****d";
private String Client_Secret= "dbdb21c0de1b***ab1d4cf6a4b92535ed2";
private String Auth_URL= "https://api.imgur.com/oauth2/authorize";
private String Access_Token_URL="https://api.imgur.com/oauth2/token";
@Test
public void oauth2() {
// Still have the same error :
Response resp = given()
.contentType("application/x-www-form-urlencoded")
.parameters("Client ID", Client_ID,
"Client Secret", Client_Secret,
"username", "testbot@gmail.com",
"password", "testbota#1",
"grant_type", "authorization_Code",
"Access_Token_URL", Access_Token_URL)
.auth()
.preemptive().basic(Client_ID, Client_Secret)
.post(Auth_URL);
}
}
答案 0 :(得分:0)
在Oauth 2.0中,grant_type是参数而不是标题。
我建议你使用这样的东西:
given().parameters("username", "testbot@gmail.com", "password", "testbota#1",
"grant_type", "Authorizaton_Code")