【发布时间】:2012-12-12 04:31:00
【问题描述】:
这个问题是我上一个问题的后续问题
我深入研究 JAVA API 以解决在 google 的 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>
此页面向我提供了一个简单的链接“连接 google 帐户”,该链接成功将我带到了 google 页面,我必须“允许”我的应用代表我访问 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"
}
我将非常感谢对此提供的任何帮助。 谢谢
【问题讨论】:
-
你能发布你发送给谷歌的请求吗?一些提琴手捕获
标签: java jsp rest google-oauth