Google Contacts API问题

时间:2013-05-13 15:04:44

标签: gwt google-api oauth-2.0 google-api-java-client google-contacts

我正在运行gwt-oauth和Google通讯录API的问题。 我使用gwt-oauth登录,一切正常。 在运行RPC以检索我得到的联系人时

WARNING: Authentication error: Unable to respond to any of these challenges: {}
java.lang.NullPointerException: No authentication header information

以下是客户端

中的代码
Button button = new Button("Authenticate with Google");
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            final AuthRequest req = new AuthRequest(K.GOOGLE_AUTH_URL, K.GOOGLE_CLIENT_ID).withScopes(K.CONTACTS_SCOPE, K.AUTH_SCOPE);
            AUTH.expiresIn(req);
            AUTH.login(req, new Callback<String, Throwable>() {
                @Override
                public void onSuccess(final String token) {
                    greetingService.loginDetails(token, new AsyncCallback<LoginInfo>() {
                        @Override
                        public void onSuccess(LoginInfo result) {

                        greetingService.getContactList(token, new AsyncCallback<Boolean>() {

                                @Override
                                public void onSuccess(Boolean result) {
                                    Window.alert("oh");
                                }

                                @Override
                                public void onFailure(Throwable caught) {
                                    Window.alert("Error:\n" + caught.getMessage());
                                }
                            });
                        }

                        @Override
                        public void onFailure(Throwable caught) {
                            // TODO Auto-generated method stub

                        }
                    });
                }

                @Override
                public void onFailure(Throwable caught) {
                    Window.alert("Error:\n" + caught.getMessage());
                }
            });
        }
    });

这里是联系人的服务器端:

    try {
        ContactsService s = new ContactsService(K.APPLICATION_NAME);
        s.setProtocolVersion(ContactsService.Versions.V3);
        s.setAuthSubToken(token);
        s.setHeader("Authorization", "Bearer " + token);
        for (ContactEntry entry : s.query(new Query(new URL(K.CONTACTS_SCOPE)), ContactFeed.class).getEntries())
            System.out.println(entry.toString());
    } catch (Exception e) {
        e.printStackTrace();
    } 
    return true;

这是几周前的工作...... 我认为不是范围问题,因为loginDetails正常工作...... 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

解决。 Auth中联系人的范围设置为:https://www.google.com/m8/feeds/contacts/default/full/ 显然这不再起作用了,我只是为了授权而设置了https://www.google.com/m8/feeds/ 以及在ContactService中查询的完整URL