gpt4 book ai didi

java - gwt-google-apis 调用结果为 "Cannot call method ' newHttpRequest' of undefined"

转载 作者:行者123 更新时间:2023-11-30 07:21:04 24 4
gpt4 key购买 nike

我正在使用 gwt-plus-v1-0.2-alpha API 来:

  1. 允许谷歌登录
  2. 获取登录用户的信息

Google 登录有效,但获取用户信息失败并显示

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-apis 库,早在 6 月份就发生了变化,将对 $wnd.googleapis.newHttpRequest() 的调用替换为对 $wnd.gapi 的调用。 client.rpcRequest(): https://code.google.com/p/gwt-google-apis/source/detail?r=2041

身份验证之所以有效,是因为它不使用相同的代码与服务器通信。

关于java - gwt-google-apis 调用结果为 "Cannot call method ' newHttpRequest' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13556641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com