java - gwt-google-apis 调用导致 "Cannot call method ' newHttpRequest' 未定义”

标签 java gwt google-plus

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

  1. 允许 Google 登录
  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 库,六月份发生了一项更改,替换了对 $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' 未定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13556641/

相关文章:

java - 如何使用java从oracle数据库中随机选择图像

java - Java-列表中的对象是否由值或引用保存?

gwt - SmartGWT Canvas 宽度问题

php - Google+ API - 检查用户帐户创建日期

java - URL 的 PATH 段中是否允许使用 "&"符号?

java - ExtJS4、Spring JPA、Restful 服务、Hibernate 应用程序

java - 如何将 spring 与 GWT 集成?

java - gwt javax.servlet.ServletContext 日志 : Exception while dispatching incoming RPC call creating mapdb db

gmail - 如何通过 Google Plus API 向人们发送电子邮件?

android - Android 中 Facebook 和 Google+ 登录的 onActivityResult 代码