2015-10-15 47 views

回答

0

我發現一個簡單的解決我的問題

public void Auth() { 
    try { 
     httpTransport = GoogleNetHttpTransport.newTrustedTransport(); 
     credential = new GoogleCredential.Builder() 
      .setTransport(httpTransport) 
      .setJsonFactory(JSON_FACTORY) 
      .setServiceAccountId(getConsumerKey()) 
      .setServiceAccountPrivateKeyFromP12File(new File(getConsumerSecret())) 
      .setServiceAccountScopes(Arrays.asList(getScope())).build(); 

     client = new Calendar.Builder(
        httpTransport, JSON_FACTORY, credential) 
        .setApplicationName(getApplicationName()).build(); 

    } 
    catch (Exception e) { 

     e.printStackTrace(); 
    } 
} 

只需在退出的Google日曆代碼中包含上述功能並從代碼中移除基於令牌的身份驗證即可。 這將工作絕對罰款與谷歌的服務帳戶。

感謝

0

看管理OAuth憑證,如果您處理這些持久對象存儲,那麼它會重用訪問令牌,而不是每次都重定向授權:https://docs.mulesoft.com/mule-user-guide/v/3.4/using-a-connector-to-access-an-oauth-api#managing-oauth-tokens-optional

+0

還是之後一段時間令牌獲取屆滿,需要刷新,這將導致一個彈出式屏幕 – sagar

+0

我使用的自動化系統生成事件的應用程序,所以我不想要基於令牌的認證,尋找服務帳戶認證 – sagar