2011-12-05 37 views
1

我正在嘗試編寫一個應用程序,使用Java API向Google添加/更新/刪除域共享聯繫人。無法使用GAE刪除域共享聯繫人Java API

我在嘗試刪除Google創建的聯繫人時遇到以下異常。

無驗證報頭信息

Caused by: 
java.lang.NullPointerException: No authentication header information 
    at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96) 
    at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67) 
    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:564) 
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:543) 
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:536) 
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:515) 
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:515) 
    at com.google.gdata.client.Service.delete(Service.java:1560) 
    at com.google.gdata.client.GoogleService.delete(GoogleService.java:691) 
    at com.google.gdata.data.BaseEntry.delete(BaseEntry.java:647) 
    at com.visy.connector.synchronizer.impl.ContactSynchronizerImpl.deleteContact(ContactSynchronizerImpl.java:170) 
    at com.visy.connector.TestServlet.doGet(TestServlet.java:54) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 

以下是我使用deleteContact

public String deleteContact(String contactId) { 

     String resultString = "Failed" 
     ContactEntry contactEntry = getContactFromGoogle(contactId); 
     try { 
       if (contactEntry != null) { 
       // deleting contact from Google 
       contactEntry.delete(); 
       resultString = "Sucess"; 
     } catch (IOException e) { 
      LOGGER.log(Level.SEVERE, e.getMessage()); 
     } catch (ServiceException e) { 
      LOGGER.log(Level.SEVERE, e.getMessage()); 
     } 
     return resultString; 
    } 


     public ContactEntry getContactFromGoogle(String contactId) { 
     ContactEntry contact = null; 
     ContactsService myService = getOAuthContactService("getContact"); 
     try { 
      String urlStr =  
           http://www.google.com/m8/feeds/contacts/mydomain/full 
           + "/" + contactId 
           + "?xoauth_requestor_id=" + domainAdminEmail; 
       contact = myService.getEntry(new URL(urlStr), 
              ContactEntry.class); 
         } 
     } catch (Exception e) { 
      LOGGER.log(Level.SEVERE, e.getMessage()); 
     } 
     return contact; 
    } 

     public ContactsService getOAuthContactService(String serviceName) { 
     final ContactsService myService = new ContactsService(serviceName); 
     GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
     oauthParameters.setScope(Scope); 
     oauthParameters.setOAuthConsumerKey(ConsumerKey); 
     oauthParameters.setOAuthConsumerSecret(secret);      OAuthSigner signer = new OAuthHmacSha1Signer(); 
     try { 
      myService.setOAuthCredentials(oauthParameters, signer); 
     } catch (OAuthException e) { 
      LOGGER.log(Level.SEVERE, e.getMessage()); 
     } 
     LOGGER.log(Level.INFO, "Created the Authenticated Contact Service"); 
     return myService; 
    } 

的代碼在上述代碼getContactFromGoogle()方法返回適當的接觸(按照日誌和調試結果)。但是,當我調用contactEntry.delete()時,會拋出「No Authentication Header Information」異常。

請幫我弄清楚代碼可能有什麼問題。

問候, Nirzari

回答

1

通過使用myService.setCredentials(用戶名,密碼)usermail或domainAdminMail密碼

有更多的3種方法,你可以使用任何使用(用戶名,密碼,令牌) 檢查它......

捕獲之前這個代碼()塊

{ 
    ContactsService myService = getOAuthContactService("getContact"); 
     try{ 
      String urlStr =http://www.google.com/m8/feeds/contacts/mydomain/full 
          + "/" + contactId 
          + "?xoauth_requestor_id=" + domainAdminEmail; 

       myService.setCredentials(username,password); 

      contact = myService.getEntry(new URL(urlStr), 
             ContactEntry.class); 
        } 
    } 
相關問題