Я хочу, чтобы код мог идентифицировать ошибки в повторяющихся событиях или событиях дублирования подписки,
Я взял приведенный выше фрагмент из фрагмента кода в начале введения API YouTube и изменил его, а именно:вставка подписки:
private List<String> getDataFromApi() throws IOException {
String channelId = "UCEgdi0XIXXZ-qJOFPf4JSKw";
// Create a resourceId that identifies the channel ID.
ResourceId resourceId = new ResourceId();
resourceId.setChannelId(channelId);
resourceId.setKind("youtube#channel");
// Create a snippet that contains the resourceId.
SubscriptionSnippet snippet = new SubscriptionSnippet();
snippet.setResourceId(resourceId);
// Create a request to add the subscription and send the request.
// The request identifies subscription metadata to insert as well
// as information that the API server should return in its response.
Subscription subscription = new Subscription();
subscription.setSnippet(snippet);
YouTube.Subscriptions.Insert subscriptionInsert =
mService.subscriptions().insert("snippet,contentDetails", subscription);
try {
Subscription returnedSubscription = subscriptionInsert.execute();
if (returnedSubscription != null){
System.out.println("\n================== Returned Subscription ==================\n");
System.out.println(" - Id: " + returnedSubscription.getId());
System.out.println(" - Title: " + returnedSubscription.getSnippet().getTitle());
etNama1.setText(returnedSubscription.getId());
etNama2.setText(returnedSubscription.getSnippet().getTitle());
}
} catch (GoogleJsonResponseException e) {
etNama1.setText(e.getDetails().getCode() + " : "
+ e.getDetails().getMessage());
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
+ e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
etNama1.setText(e.getMessage());
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
etNama1.setText(t.getMessage());
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
// Print information from the API response.
return null;
}