我有这个错误:

WARNING: Authentication error: Unable to respond to any of these challenges: {}
Exception : No authentication header information


我正在使用GWT和Eclipse。
我真的不知道我的代码有什么问题。
任何帮助,将不胜感激。

提前致谢。

客户端EntryPoint类:

private static final String GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
private static final String GOOGLE_CLIENT_ID = "xxxxxxx.apps.googleusercontent.com";
private static final String CONTACTS_SCOPE = "https://www.google.com/m8/feeds";
private static final Auth AUTH = Auth.get();

public void onModuleLoad() {
        final AuthRequest req = new AuthRequest(GOOGLE_AUTH_URL, GOOGLE_CLIENT_ID).withScopes(CONTACTS_SCOPE);

    AUTH.login(req, new Callback<String, Throwable>() {
        public void onSuccess(String token) {
            ABASession.setToken(token);
        }

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


我将令牌存储在稍后将使用的类中。

服务器端:ContactServiceImpl(RPC GAE过程)

//先前存储的令牌然后通过RPC传递
    公共列表printAllContacts(String token){
        尝试{
            GoogleOAuthParameters oauthParameters =新的GoogleOAuthParameters();

        oauthParameters.setOAuthConsumerKey("My consumer key");
        oauthParameters.setOAuthConsumerSecret("My consumer secret");

        PrivateKey privKey = getPrivateKey("certificate/akyosPrivateKey.key");

        OAuthRsaSha1Signer signer = new OAuthRsaSha1Signer(privKey);

        ContactsService service = new ContactsService("XXX");
        service.setProtocolVersion(ContactsService.Versions.V3);
        oauthParameters.setOAuthToken(token);
        service.setOAuthCredentials(oauthParameters, signer);

        // Request the feed
        URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/default/full?xoauth_requestor_id=xxx.yyy@gmail.com");

        ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
        for (ContactEntry entry : resultFeed.getEntries()) {
            for (Email email : entry.getEmailAddresses()) {
                contactNames.add(email.getAddress());
            }
        }
        return contactNames;
    } catch (Exception e) {
        System.err.println("Exception : " + e.getMessage());
    }
    return null;
}

最佳答案

设定范围

oauthParameters.setScope("http://www.google.com/m8/feeds/contacts/default/full");

关于java - GAE OAuth Java:没有身份验证 header 信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8578517/

10-12 00:12
查看更多