I'm testing Google Calendar authentication-related logic in Java. I'm not sure if I'm misunderstanding the concept, but I've been unable to resolve the issue for several days now.
My code is as follows:
GoogleAPI.java
private static final Logger LOGGER = LoggerFactory.getLogger(GoogleAPI.class);
private static final String APPLICATION_NAME = "Your Application Name";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = EgovProperties.getProperty("Globals.google.api.calendar.token");
private static final String CLIENT_SECRETS_FILE_PATH = EgovProperties.getProperty("Globals.google.api.calendar");
public static GoogleAuthorizationCodeFlow FLOW;
public static LocalServerReceiver RECEIVER;
public static Credential getCredential() throws IOException, GeneralSecurityException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
InputStream in = GoogleAPI.class.getResourceAsStream(CLIENT_SECRETS_FILE_PATH);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
FLOW = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
Collections.singletonList(CalendarScopes.CALENDAR))
.setDataStoreFactory(new FileDataStoreFactory(new File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
RECEIVER = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(FLOW, RECEIVER).authorize("user");
}
public static List<TodolistVO> listEvents(String calendarId) throws GeneralSecurityException, IOException {
List<TodolistVO> rtnList = new ArrayList<TodolistVO>();
try {
Calendar service = new Calendar.Builder(new NetHttpTransport(), JSON_FACTORY, getCredential())
.setApplicationName(APPLICATION_NAME)
.build();
Events events = service.events().list(calendarId).execute();
List<Event> items = events.getItems();
for(Event evt : items) {
TodolistVO vo = new TodolistVO();
vo.setTitle(evt.getSummary());
}
} catch (Exception e) {
e.printStackTrace();
}
return rtnList;
}
The situation is as follows:
There is another situation here:
It works when I delete the file, but something doesn't work correctly when the file is still present. How can I resolve this issue?
Please let me know if you need further assistance with this problem.
Using ChatGPT for translation might make the question content seem unusual at times.
I would really appreciate it if you could answer.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4