Email Settings API - ClientLogin

送分小仙女□ 提交于 2019-12-13 04:32:32

问题


We are using EMAIL Settings API and ClientLogin for Authentication. EMAIL Settings API is still on GDATA Libraries. Using GDATA libraries can we start using OAuth 2.0 ? (we are using the appsforyourdomain client library to use EMAIL Settings API) Or can we continue using ClientLogin ? Based on the post looks like ClientLogin is going to retire by April 20, 2015. Please guide me the right approach. GDATA API : 1.46.0. EMAIL Settings API is used only for disabling the webclips for the user.


回答1:


We were using GDATA API 1.46.0 and it does not support OAuth 2.0 . Support was added in 1.47.0 version. See the release note below. After using the new Libraries I was able to implement OAuth 2.0. Used GmailSettingsService class inside the appsforyourdomain client library and commented out the ClientLogin flow and added new flow for OAuth2.0. Use GoogleCredential Object to create the OAuth2.0 credential object.

//  Client Login
//  this.setUserCredentials(username + "@" + domain, password);

//  OAuth 2.0
this.setOAuth2Credentials(initCredential());

public static GoogleCredential initCredential() throws GeneralSecurityException, IOException {
      httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    List<String> scopes = Arrays.asList("https://apps-apis.google.com/a/feeds/emailsettings/2.0/");

    credential = new GoogleCredential.Builder()
        .setTransport(httpTransport)
        .setJsonFactory(JSON_FACTORY)
        .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
        .setServiceAccountScopes(scopes)
        .setServiceAccountPrivateKeyFromP12File(new File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
        .setServiceAccountUser(DOMAIN_ADMIN_API_USER)
        .build();  
    return credential;
  }

Notes for v1.47.0

o Add OAuth 2.0 support leveraging Google OAuth Client for Java (http://code.google.com/p/google-oauth-java-client/).



来源:https://stackoverflow.com/questions/28704447/email-settings-api-clientlogin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!