這個問題是在跟進我剛纔的問題谷歌的OAuth Java客戶端得到一個訪問令牌失敗,「400錯誤的請求{」錯誤「:」 INVALID_REQUEST「}」
我跳入水中到JAVA API來解決在谷歌的oAuth API中交換authToken代碼的問題,但無法找出答案。因此,我走了一條非常簡單的路線。
我創建了以下的JSP
的index.jsp
<%@page import="java.net.URLEncoder"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<a href="https://accounts.google.com/o/oauth2/auth?
scope=https://gdata.youtube.com/&
redirect_uri=<%=URLEncoder.encode("http://localhost:8080/BroadCastr/step2.jsp","UTF-8")%>&
response_type=code&
client_id=X985XXXXXXXX.apps.googleusercontent.com&approval_prompt=force">Connect google account</a>
</body>
</html>
本頁面我提出了一個簡單的鏈接「連接谷歌帳戶」,這給我帶來了成功,以谷歌的網頁,我不得不「允許」我應用訪問YouTube的代表我
在step2.jsp
<%@page import="java.net.URLEncoder"%>
<%@page import="java.util.Iterator"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form id="frm" method="post" action="https://accounts.google.com/o/oauth2/token" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="code" value="<%=URLEncoder.encode(request.getParameter("code"),"UTF-8")%>"/>
<input type="hidden" name="client_id" value="XXXXXXXXXXX.apps.googleusercontent.com"/>
<input type="hidden" name="client_secret" value="XXXXxxxxXXXXXX"/>
<input type="hidden" name="redirect_uri" value="<%=URLEncoder.encode("http://localhost:8080/BroadCastr/step3.jsp","UTF-8")%>"/>
<input type="hidden" name="grant_type" value="authorization_code"/>
<input type="hidden" name="scope" value=""/>
</form>
</body>
</html>
<script>
document.getElementById("frm").submit();
</script>
但最後step2.jsp提交自己谷歌的服務器我得到的是以下無益的JSON
{
"error": "invalid_request"
}
我會很感激在這一個任何幫助。 謝謝
你能發佈要求你發送到谷歌?一些提琴手捕獲 – Vlad