Java gwt google API调用导致“无法调用未定义的'newHttpRequest'方法”
我正在使用gwt-plus-v1-0.2-alpha API来: 允许谷歌登录 获取已登录用户的信息 Google登录可以正常工作,但获取用户信息失败,原因是Java gwt google API调用导致“无法调用未定义的'newHttpRequest'方法”,java,gwt,google-plus,Java,Gwt,Google Plus,我正在使用gwt-plus-v1-0.2-alpha API来: 允许谷歌登录 获取已登录用户的信息 Google登录可以正常工作,但获取用户信息失败,原因是 Cannot call method 'newHttpRequest' of undefined 错误 以下是我的GoogleApi助手类: public final class GoogleApi { private static final Plus plus = GWT.create(Plus.class); p
Cannot call method 'newHttpRequest' of undefined
错误
以下是我的GoogleApi助手类:
public final class GoogleApi {
private static final Plus plus = GWT.create(Plus.class);
private final String clientId;
private final ClientOAuth2Login oAuth2Login;
private ClientGoogleApiRequestTransport requestTransport;
/**
* @param clientId
* This app's personal client ID assigned by the Google APIs
* Console (http://code.google.com/apis/console)
*/
public GoogleApi(EventBus eventBus, String clientId) {
this.clientId = clientId;
requestTransport = new ClientGoogleApiRequestTransport();
requestTransport.setApplicationName(MY_APP_NAME)
.setApiAccessKey(MY_API_KEY);
plus.initialize(eventBus, requestTransport);
oAuth2Login = new ClientOAuth2Login(clientId);
oAuth2Login.withScopes(PlusAuthScope.PLUS_ME);
}
public void login(final Receiver<String> callback) {
oAuth2Login.login(new Receiver<String>() {
@Override
public void onSuccess(String response) {
requestTransport.setAccessToken(response);
callback.onSuccess(response);
}
@Override
public void onFailure(ServerFailure error) {
Window.alert(error.getMessage());
}
});
}
public void getUserInfo(Receiver<Person> receiver) {
plus.people().get("me").to(receiver).fire();
}
}
以下显示了故障发生的位置:
GoogleApi googleApi = new GoogleApi(eventBus, MY_CLIENT_ID);
googleApi.login(new Receiver<String>() {
@Override
public void onSuccess(final String token) {
// login is successful and access token is received
// but the following call fails with "Cannot call method 'newHttpRequest'
// of undefined" error
googleApi.getUserInfo(new Receiver<Person>() {
@Override
public void onSuccess(Person person) {
// never gets here
}
@Override
public void onFailure(ServerFailure error) {
// nor here
}
});
}
}
尝试更新您的gwt google API库,早在6月份就有了一项更改,将对$wnd.googleapis.newHttpRequest的调用替换为对$wnd.gapi.client.rpcRequest的调用:
身份验证之所以有效,是因为它不使用相同的代码与服务器通信。尝试更新您的gwt google API库,6月份发生了一次更改,将对$wnd.googleapis.newHttpRequest的调用替换为对$wnd.gapi.client.rpcRequest的调用:
身份验证之所以有效,是因为它不使用相同的代码与服务器进行通信。我一直在使用1.0.2-alpha版本的代码,并使其有效!以下是更新的代码:
public final class GoogleApi {
private static final Plus plus = GWT.create(Plus.class);
private final String clientId;
private EventBus eventBus;
private final ClientOAuth2Login oAuth2Login;
private ClientGoogleApiRequestTransport requestTransport;
private String accessToken;
/**
* @param clientId
* This app's personal client ID assigned by the Google APIs
* Console (http://code.google.com/apis/console)
*/
public GoogleApi(final EventBus eventBus, String clientId) {
this.eventBus = eventBus;
this.clientId = clientId;
oAuth2Login = new ClientOAuth2Login(clientId);
oAuth2Login.withScopes(PlusAuthScope.PLUS_ME);
}
public void login(final Receiver<String> callback) {
oAuth2Login.login(new Receiver<String>() {
@Override
public void onSuccess(String response) {
accessToken = response;
callback.onSuccess(response);
}
@Override
public void onFailure(ServerFailure error) {
Window.alert(error.getMessage());
}
});
}
public void getUserInfo(final Receiver<Person> receiver) {
requestTransport = new ClientGoogleApiRequestTransport();
requestTransport.setApplicationName(ClientConstants.GOOGLE_APP_NAME)
.setApiAccessKey(ClientConstants.GOOGLE_API_KEY)
.setAccessToken(accessToken);
requestTransport.create(new Receiver<GoogleApiRequestTransport>() {
@Override
public void onSuccess(GoogleApiRequestTransport transport) {
plus.initialize(eventBus, transport);
plus.people().get("me").to(receiver).fire();
}
});
}
}
不过,我不知道这有多有效。每次调用getUserInfo时,都会调用Plus的initialize方法
对我来说,下一步是用最新版本的API手动构建一个jar,并相应地调整我的代码:/bick me luck 我一直在使用1.0.2-alpha版本的代码,并使其正常工作!以下是更新的代码:
public final class GoogleApi {
private static final Plus plus = GWT.create(Plus.class);
private final String clientId;
private EventBus eventBus;
private final ClientOAuth2Login oAuth2Login;
private ClientGoogleApiRequestTransport requestTransport;
private String accessToken;
/**
* @param clientId
* This app's personal client ID assigned by the Google APIs
* Console (http://code.google.com/apis/console)
*/
public GoogleApi(final EventBus eventBus, String clientId) {
this.eventBus = eventBus;
this.clientId = clientId;
oAuth2Login = new ClientOAuth2Login(clientId);
oAuth2Login.withScopes(PlusAuthScope.PLUS_ME);
}
public void login(final Receiver<String> callback) {
oAuth2Login.login(new Receiver<String>() {
@Override
public void onSuccess(String response) {
accessToken = response;
callback.onSuccess(response);
}
@Override
public void onFailure(ServerFailure error) {
Window.alert(error.getMessage());
}
});
}
public void getUserInfo(final Receiver<Person> receiver) {
requestTransport = new ClientGoogleApiRequestTransport();
requestTransport.setApplicationName(ClientConstants.GOOGLE_APP_NAME)
.setApiAccessKey(ClientConstants.GOOGLE_API_KEY)
.setAccessToken(accessToken);
requestTransport.create(new Receiver<GoogleApiRequestTransport>() {
@Override
public void onSuccess(GoogleApiRequestTransport transport) {
plus.initialize(eventBus, transport);
plus.people().get("me").to(receiver).fire();
}
});
}
}
不过,我不知道这有多有效。每次调用getUserInfo时,都会调用Plus的initialize方法
对我来说,下一步是用最新版本的API手动构建一个jar,并相应地调整我的代码:/bick me luck 谢谢你的回复,托马斯。是否有包含这些最新更改的可下载jar?我能找到的最新版本是3月份的v1.0.3。我无法使用最新版本的API,因此我将不得不使用我在自己的答案中粘贴的代码以及gwt-plus-v1.0.2-alpha。谢谢你的回复,Thomas。是否有包含这些最新更改的可下载jar?我能找到的最新版本是3月份的v1.0.3。我无法使用最新版本的API,因此我将不得不使用我在自己的答案中粘贴的代码以及gwt-plus-v1.0.2-alpha.jar