【发布时间】:2012-03-16 06:15:00
【问题描述】:
从 OathCallBack 页面中的以下 URL,我想使用 Java 提取 access_token 和 token_type。知道怎么做吗?
我尝试了以下方法,但无法提取所需信息。
{
String scheme = req.getScheme(); // http
String serverName = req.getServerName(); // myserver.com
int serverPort = req.getServerPort(); // 80
String contextPath = req.getContextPath();
String servletPath = req.getServletPath();
String pathInfo = req.getPathInfo(); // return null and exception
String queryString = req.getQueryString(); // return null
}
我要编辑我的问题
感谢大家的精彩回复,
谷歌做到了,
您可以通过 URL 引用该链接
http://developers.google.com/accounts/docs/OAuth2Login
上面的网址页面有以下链接
http://accounts.google.com/o/oauth2/auth?范围=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile& state=%2Fprofile& redirect_uri=https%3A%2F% 2Foauth2-login-demo.appspot.com%2Foauthcallback& response_type=token& client_id=812741506391.apps.googleusercontent.com
当您点击上面的链接时,您将获得您的 gmail 登录帐户 access_token,并且该令牌在#sign 之后
【问题讨论】:
-
在 URL 中的 "?" 位置是“#”,因此查询字符串不会被提取,如果我能够读取/获取字符串中的整个 URL,它将被提取,如何读取包括所有内容的完整 URL,例如 access_token
-
你试过req.getRequestURL()
-
req.getRequestURL() 仅检索 myserver.com/OathCallBack 并没有其他内容,但我对其他参数感兴趣,例如 access_token 等
-
我编辑了原始问题,请参考
标签: java google-app-engine url web query-string