0
如何將嵌入式YouTube訂閱按鈕添加到我的Android應用程序?我需要一個按鈕,將它們訂閱到我的頻道,但保留在我的應用程序中,如web按鈕,但是用於android。我嘗試了訂閱鏈接,但它將它們從我的應用程序中取出。如何實現嵌入式YouTube的訂閱按鈕android?
如何將嵌入式YouTube訂閱按鈕添加到我的Android應用程序?我需要一個按鈕,將它們訂閱到我的頻道,但保留在我的應用程序中,如web按鈕,但是用於android。我嘗試了訂閱鏈接,但它將它們從我的應用程序中取出。如何實現嵌入式YouTube的訂閱按鈕android?
使用Youtube Data API中的subscriptions.insert爲已認證用戶的頻道添加訂閱。當按下按鈕時,執行這部分代碼。
代碼片段:
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());
}
這裏有一個額外的參考相關SO thread。
有沒有一個應用程序的來源,我可以看看學習? –