Google Gdata ContactService Oauth2 Java

Google Gdata ContactService Oauth2 Java,java,oauth-2.0,gdata,google-shared-contacts,Java,Oauth 2.0,Gdata,Google Shared Contacts,编辑: 我问题的解决方案显示。。。好吧,千万不要不经思考就尝试使用复制粘贴代码 解决方案 为了能够改变我的服务,服务永远不应该是最终的。删除最终启用的setCredentials(凭据)并让我联系我的联系人 正确的联系人服务初始化: /** * Service used to communicate with contacts feed. */ private ContactsService service = new ContactsService(APPLICATION_NAME);

编辑: 我问题的解决方案显示。。。好吧,千万不要不经思考就尝试使用复制粘贴代码

解决方案

为了能够改变我的服务,服务永远不应该是最终的。删除最终启用的setCredentials(凭据)并让我联系我的联系人

正确的联系人服务初始化:

/**
 * Service used to communicate with contacts feed.
 */
private ContactsService service = new ContactsService(APPLICATION_NAME);
在此之后,没有出现任何错误;)

原始问题

@Override
public Integer importGoogleContactData() 
{
    int numberOfImportedContacts = 0;
    System.out.println( "INFO GDataServiceImpl reached importGoogleContactData()");
    try 
    {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        //authorization
        Credential credential = authorize();
        credential.refreshToken();

        System.out.println( "INFO credential = getAccessToken() " + credential.getAccessToken() );
        System.out.println( "INFO credential = getRefreshToken() " + credential.getRefreshToken() );

        service.setOAuth2Credentials(credential);
        service.useSsl();
        System.out.println( "INFO service = getServiceVersion() " + service.getServiceVersion() );

        feedUrl = new URL( "https://www.google.com/m8/feeds/contacts/default/full" );
        System.out.println("INFO url: " + feedUrl.toString() );

        ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
        // Print the results
        System.out.println(resultFeed.getTitle().getPlainText());
        for (ContactEntry entry : resultFeed.getEntries())
        {
            numberOfImportedContacts++;
            System.out.println("INFO found Contact: " + entry.getName() );
        }
    } 
    catch (IOException e) 
    {
        System.err.println(e.getMessage());
    } 
    catch (Throwable t) 
    {
        t.printStackTrace();
    }
    return numberOfImportedContacts;
}
我正在尝试构建一个GWT服务器端调用Google GData Contacts API V3.0。 我正在使用GWT2.5.1和jre6。为此,我想实现本机应用程序的API。不是作为web服务器服务

我确实收到*访问令牌*和*刷新令牌*

我希望能够读取/更新/删除联系人,并将其与我的数据库同步

尽管我发现了几个问题,但没有针对本机应用程序方法的解决方案或问题

谢谢大家的帮助

我的问题

ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
只会导致错误:

15:12:41,513 ERROR [STDERR] java.lang.NullPointerException: No authentication header information
15:12:41,514 ERROR [STDERR]     at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)

我的问题

@Override
public Integer importGoogleContactData() 
{
    int numberOfImportedContacts = 0;
    System.out.println( "INFO GDataServiceImpl reached importGoogleContactData()");
    try 
    {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        //authorization
        Credential credential = authorize();
        credential.refreshToken();

        System.out.println( "INFO credential = getAccessToken() " + credential.getAccessToken() );
        System.out.println( "INFO credential = getRefreshToken() " + credential.getRefreshToken() );

        service.setOAuth2Credentials(credential);
        service.useSsl();
        System.out.println( "INFO service = getServiceVersion() " + service.getServiceVersion() );

        feedUrl = new URL( "https://www.google.com/m8/feeds/contacts/default/full" );
        System.out.println("INFO url: " + feedUrl.toString() );

        ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
        // Print the results
        System.out.println(resultFeed.getTitle().getPlainText());
        for (ContactEntry entry : resultFeed.getEntries())
        {
            numberOfImportedContacts++;
            System.out.println("INFO found Contact: " + entry.getName() );
        }
    } 
    catch (IOException e) 
    {
        System.err.println(e.getMessage());
    } 
    catch (Throwable t) 
    {
        t.printStackTrace();
    }
    return numberOfImportedContacts;
}
还有其他人收到这些问题吗

我是否可以使用
com.google.api.client.auth.oauth2.Credential
来授权
联系人服务

有没有办法自己创建这个标题作为解决方法

我的代码包括导入:

联系人服务初始化

private final ContactsService service = new ContactsService(APPLICATION_NAME);
导入功能

@Override
public Integer importGoogleContactData() 
{
    int numberOfImportedContacts = 0;
    System.out.println( "INFO GDataServiceImpl reached importGoogleContactData()");
    try 
    {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        //authorization
        Credential credential = authorize();
        credential.refreshToken();

        System.out.println( "INFO credential = getAccessToken() " + credential.getAccessToken() );
        System.out.println( "INFO credential = getRefreshToken() " + credential.getRefreshToken() );

        service.setOAuth2Credentials(credential);
        service.useSsl();
        System.out.println( "INFO service = getServiceVersion() " + service.getServiceVersion() );

        feedUrl = new URL( "https://www.google.com/m8/feeds/contacts/default/full" );
        System.out.println("INFO url: " + feedUrl.toString() );

        ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
        // Print the results
        System.out.println(resultFeed.getTitle().getPlainText());
        for (ContactEntry entry : resultFeed.getEntries())
        {
            numberOfImportedContacts++;
            System.out.println("INFO found Contact: " + entry.getName() );
        }
    } 
    catch (IOException e) 
    {
        System.err.println(e.getMessage());
    } 
    catch (Throwable t) 
    {
        t.printStackTrace();
    }
    return numberOfImportedContacts;
}
授权()

完成服务器输出:

2014-03-05 15:37:53,759 INFO  [STDOUT] (http-0.0.0.0-8080-4) INFO GDataServiceImpl reached importGoogleContactData()

2014-03-05 15:37:53,798 WARNING [com.google.api.client.util.store.FileDataStoreFactory] (http-0.0.0.0-8080-4) unable to change permissions for everybody: C:\Users\evergrin\.store\oauth2
2014-03-05 15:37:53,799 WARNING [com.google.api.client.util.store.FileDataStoreFactory] (http-0.0.0.0-8080-4) unable to change permissions for owner: C:\Users\evergrin\.store\oauth2
2014-03-05 15:37:54,333 INFO  [STDOUT] (http-0.0.0.0-8080-4) INFO credential = getAccessToken() <ACCESS_TOKEN>
2014-03-05 15:37:54,334 INFO  [STDOUT] (http-0.0.0.0-8080-4) INFO credential = getRefreshToken() <REFRESH_TOKEN>
2014-03-05 15:37:54,336 INFO  [STDOUT] (http-0.0.0.0-8080-4) INFO service = getServiceVersion() GContacts-Java/3.1.0 GData-Java/1.47.1(gzip)
2014-03-05 15:37:54,336 INFO  [STDOUT] (http-0.0.0.0-8080-4) INFO url: https://www.google.com/m8/feeds/contacts/default/full
2014-03-05 15:37:54,476 ERROR [STDERR] (http-0.0.0.0-8080-4) java.lang.NullPointerException: No authentication header information
2014-03-05 15:37:54,477 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
2014-03-05 15:37:54,486 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67)
2014-03-05 15:37:54,487 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608)
2014-03-05 15:37:54,487 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
2014-03-05 15:37:54,487 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
2014-03-05 15:37:54,487 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
2014-03-05 15:37:54,487 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.Service.getFeed(Service.java:1135)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.Service.getFeed(Service.java:998)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gdata.client.Service.getFeed(Service.java:1017)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at sung.app.dieligen.dropkick.gwt.server.gdata.GDataServiceImpl.importGoogleContactData(GDataServiceImpl.java:185)
2014-03-05 15:37:54,488 ERROR [STDERR] (http-0.0.0.0-8080-4)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2014-03-05 15:37:54,489 ERROR [STDERR] (http-0.0.0.0-8080-4)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2014-03-05 15:37:54,489 ERROR [STDERR] (http-0.0.0.0-8080-4)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2014-03-05 15:37:54,489 ERROR [STDERR] (http-0.0.0.0-8080-4)    at java.lang.reflect.Method.invoke(Method.java:606)
2014-03-05 15:37:54,489 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
2014-03-05 15:37:54,489 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
2014-03-05 15:37:54,490 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
2014-03-05 15:37:54,491 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
2014-03-05 15:37:54,491 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
2014-03-05 15:37:54,491 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
2014-03-05 15:37:54,491 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
2014-03-05 15:37:54,492 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
2014-03-05 15:37:54,492 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
2014-03-05 15:37:54,492 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
2014-03-05 15:37:54,492 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2014-03-05 15:37:54,492 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
2014-03-05 15:37:54,493 ERROR [STDERR] (http-0.0.0.0-8080-4)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
2014-03-05 15:37:54,494 ERROR [STDERR] (http-0.0.0.0-8080-4)    at java.lang.Thread.run(Thread.java:744)
2014-03-05 15:37:53759信息[STDOUT](http-0.0.0-8080-4)信息GdatServiceImpl已到达importGoogleContactData()
2014-03-05 15:37:53798警告[com.google.api.client.util.store.FileDataStoreFactory](http-0.0.0-8080-4)无法更改每个人的权限:C:\Users\evergrin\.store\oauth2
2014-03-05 15:37:53799警告[com.google.api.client.util.store.FileDataStoreFactory](http-0.0.0-8080-4)无法更改所有者的权限:C:\Users\evergrin\.store\oauth2
2014-03-05 15:37:54333信息[STDOUT](http-0.0.0-8080-4)信息凭证=getAccessToken()
2014-03-05 15:37:54334 INFO[STDOUT](http-0.0.0-8080-4)INFO-credential=getRefreshToken()
2014-03-05 15:37:54336 INFO[STDOUT](http-0.0.0-8080-4)INFO service=getServiceVersion()GContacts Java/3.1.0 GData Java/1.47.1(gzip)
2014-03-05 15:37:54336信息[标准输出](http-0.0.0-8080-4)信息url:https://www.google.com/m8/feeds/contacts/default/full
2014-03-05 15:37:54476错误[STDERR](http-0.0.0-8080-4)java.lang.NullPointerException:无身份验证标头信息
2014-03-05 15:37:54477错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
2014-03-05 15:37:54486错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.util.AuthenticationException.(AuthenticationException.java:67)
2014-03-05 15:37:54487错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608)
2014-03-05 15:37:54487错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
2014-03-05 15:37:54487错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
2014-03-05 15:37:54487错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
2014-03-05 15:37:54487错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
2014-03-05 15:37:54488错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.Service.getFeed(Service.java:1135)
2014-03-05 15:37:54488错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.Service.getFeed(Service.java:998)
2014-03-05 15:37:54488错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
2014-03-05 15:37:54488错误[STDERR](http-0.0.0-8080-4)位于com.google.gdata.client.Service.getFeed(Service.java:1017)
2014-03-05 15:37:54488 sung.app.dieligen.dropkick.gwt.server.gdata.GDataServiceImpl.importGoogleContactData(GDataServiceImpl.java:185)处的错误[STDERR](http-0.0.0.0-8080-4)
2014-03-05 15:37:54488 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处的错误[STDERR](http-0.0.0-8080-4)
2014-03-05 15:37:54489 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)上的错误[STDERR](http-0.0.0.0-8080-4)
2014-03-05 15:37:54489 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)处的错误[STDERR](http-0.0.0-8080-4)
2014-03-05 15:37:54489 java.lang.reflect.Method.invoke(Method.java:606)处的错误[STDERR](http-0.0.0-8080-4)
2014-03-05 15:37:54489错误[STDERR](http-0.0.0-8080-4)位于com.google.gwt.user.server.rpc.rpc.invokeAndEncodeResponse(rpc.java:561)
2014-03-05 15:37:54489错误[STDERR](http-0.0.0-8080-4)位于com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
2014-03-05 15:37:54490错误[STDERR](http-0.0.0-8080-4)位于com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
2014-03-05 15:37:54490错误[STDERR](http-0.0.0-8080-4)位于com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
2014-03-05 15:37:54490 javax.servlet.http.HttpServlet.service(HttpServlet.java:754)上的错误[STDERR](http-0.0.0-8080-4)
2014-03-05 15:37:54490 javax.servlet.http.HttpServlet.service(HttpServlet.java:847)上的错误[STDERR](http-0.0.0-8080-4)
2014-03-05 15:37:54490错误[STDERR](http-0.0.0-8080-4)位于org.apache.catalina.core.applicationlte