Trying to get Gmail service and it should up the message 'com.google.api.client.googleapis.auth.oauth2.GoogleCredential' is deprecated.
Here is my code snippet.
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.gmail.Gmail;
import org.json.JSONException;
import org.json.JSONObject;
public Gmail getGmailService() throws Exception {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(SecurityConstant.CREDENTIALS.concat(environment).concat(SecurityConstant.JSON_EXTENSION));
try {
if (null != inputStream) {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(inputStream));
String clientId = clientSecrets.getDetails().getClientId();
String clientSecret = clientSecrets.getDetails().getClientSecret();
Credential authorize = new **GoogleCredential**.Builder().setTransport(GoogleNetHttpTransport.newTrustedTransport())
.setJsonFactory(JSON_FACTORY)
.setClientSecrets(clientId,
clientSecret)
.build().setAccessToken(getAccessToken(clientId, clientSecret, refreshToken));
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
inputStream.close();
return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, authorize)
.setApplicationName(SecurityConstant.MODULE_NAME).build();
}
} catch (IOException | GeneralSecurityException exception) {
exception.printStackTrace();
}
return null;
}