Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Just a tiny bit of "error handling"
Browse files Browse the repository at this point in the history
  • Loading branch information
Stekeblad committed May 1, 2020
1 parent 7e86d38 commit 5b64e25
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/github/stekeblad/videouploader/youtube/Auth.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.stekeblad.videouploader.youtube;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.auth.oauth2.TokenResponseException;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
Expand All @@ -19,6 +20,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -70,6 +73,18 @@ public static String getChannelName() {
ChannelListResponse channelListResponse = myChannel.execute();
List<Channel> channelList = channelListResponse.getItems();
return channelList.get(0).getSnippet().getTitle();
} catch (TokenResponseException tre) {
// This can occur if the "Token has been expired or revoked." (quoting an error message)
// Delete the token and on next attempt try authenticate again.
// Thrown from Channels.List.execute() and not from Auth.authUser()
try {
if (Files.deleteIfExists(Paths.get(AUTH_DIR, "StoredCredential")))
System.err.println("deleted invalid token");
else
System.err.println("Failed to delete invalid token");
} catch (Exception ignored) {
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
Expand Down

0 comments on commit 5b64e25

Please sign in to comment.