2016-09-01 2 views

Répondre

1

Utilisez subscriptions.insert à partir de l'API de données YouTube pour ajouter un abonnement au canal de l'utilisateur authentifié. Faites en sorte que lorsque le bouton est pressé, cette partie du code s'exécute.

extrait de code:

try { 
     // Authorize the request. 
     Credential credential = Auth.authorize(scopes, "addsubscription"); 

     // This object is used to make YouTube Data API requests. 
     youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName(
       "youtube-cmdline-addsubscription-sample").build(); 

     // We get the user selected channel to subscribe. 
     // Retrieve the channel ID that the user is subscribing to. 
     String channelId = getChannelId(); 
     System.out.println("You chose " + channelId + " to subscribe."); 

     // 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 = 
       youtube.subscriptions().insert("snippet,contentDetails", subscription); 
     Subscription returnedSubscription = subscriptionInsert.execute(); 

     // Print information from the API response. 
     System.out.println("\n================== Returned Subscription ==================\n"); 
     System.out.println(" - Id: " + returnedSubscription.getId()); 
     System.out.println(" - Title: " + returnedSubscription.getSnippet().getTitle()); 

    } 

est ici un SO thread connexe de référence supplémentaire.

+0

Y a-t-il une source d'applications où que je puisse regarder? –