有没有人能帮我用OAuth2认证Google Plus?我可以让身份验证窗口显示、登录并使用我的帐户确认我的应用程序,但由于某些原因,操作事件从未触发。我看到一个屏幕,说请复制此代码,切换到您的应用程序并将其粘贴到那里。
如何触发action事件?
提前谢谢。
编辑:
我的代码如下:
嗨,谢谢你的回复,我的认证代码如下:
Oauth2 auth2 = new Oauth2("https://accounts.google.com/o/oauth2/auth", "Client_Id", "urn:ietf:wg:oauth:2.0:oob or http://localhost", "openid", "https://accounts.google.com/o/oauth2/token", "Client_Secret");
Oauth2.setBackToParent(true);
auth2.showAuthentication(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof String) {
String token = (String) evt.getSource();
String expires = Oauth2.getExpires();
GOOGLE_TOKEN = token;
System.out.println("recived a token " + token + " which expires on " + expires);
//store token for future queries.
} else {
Exception err = (Exception) evt.getSource();
err.printStackTrace();
Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null);
}
}
});"auth2.showAuthentication“运行良好,允许您传递给用户授权应用程序,但是一旦用户授权应用程序,"actionlistener”就不会被调用,我就再也不会触发回调。如何强制触发回调以返回令牌?
发布于 2015-03-13 21:06:40
我一直在为同样的问题而苦苦挣扎。我最终发现问题出在Oauth2.createLoginComponent()内部的WebBrowser设置上:onStart()处理程序等待以您提供的重定向URI开头的URL,但此URL从未出现。最后一个带令牌的谷歌页面的网址以"https://accounts.google.com/o/oauth2/approval?"开头,而不是以重定向URI开头。
根据Google's documentation的说法,令牌将在页面标题中提供,但CodeName One中的本机浏览器似乎不是这种情况。因此,我最终从HTML文档中抓取了一个带有id="code"的input,它的值就是我们要查找的令牌。抓取必须在页面加载后发生,即在onLoad()事件中,而不是在onStart()中。
希望这对我有帮助,它对我很有效。
https://stackoverflow.com/questions/18579856
复制相似问题