static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("AdSense Management API Command Line Sample"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new AdsenseService(auth); var accounts = GetAllAccounts.Run(service, MaxListPageSize); if (accounts.Items != null && accounts.Items.Count > 0) { // Get an example account ID, so we can run the following samples. var exampleAccountId = accounts.Items[0].Id; GetAccountTree.Run(service, exampleAccountId); GetAllAdClientsForAccount.Run(service, exampleAccountId, MaxListPageSize); } var adClients = GetAllAdClients.run(service, MaxListPageSize); if (adClients.Items != null && adClients.Items.Count > 0) { // Get an ad client ID, so we can run the rest of the samples. var exampleAdClientId = adClients.Items[0].Id; var adUnits = GetAllAdUnits.Run(service, exampleAdClientId, MaxListPageSize); if (adUnits.Items != null && adUnits.Items.Count > 0) { // Get an example ad unit ID, so we can run the following sample. var exampleAdUnitId = adUnits.Items[0].Id; GetAllCustomChannelsForAdUnit.Run(service, exampleAdClientId, exampleAdUnitId, MaxListPageSize); } var customChannels = GetAllCustomChannels.Run(service, exampleAdClientId, MaxListPageSize); if (customChannels.Items != null && customChannels.Items.Count > 0) { // Get an example custom channel ID, so we can run the following sample. var exampleCustomChannelId = customChannels.Items[0].Id; GetAllAdUnitsForCustomChannel.Run(service, exampleAdClientId, exampleCustomChannelId, MaxListPageSize); } GetAllUrlChannels.Run(service, exampleAdClientId, MaxListPageSize); GenerateReport.Run(service, exampleAdClientId); GenerateReportWithPaging.Run(service, exampleAdClientId, MaxReportPageSize); } CommandLine.PressAnyKeyToExit(); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API: E-Tag collision"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new TasksService(auth); // Run the sample code. RunSample(service, true, ETagAction.Ignore); RunSample(service, true, ETagAction.IfMatch); RunSample(service, true, ETagAction.IfNoneMatch); RunSample(service, false, ETagAction.Ignore); RunSample(service, false, ETagAction.IfMatch); RunSample(service, false, ETagAction.IfNoneMatch); CommandLine.PressAnyKeyToExit(); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new TasksService(auth); TaskLists results = service.Tasklists.List().Fetch(); CommandLine.WriteLine(" ^1Lists:"); foreach (TaskList list in results.Items) { CommandLine.WriteLine(" ^2" + list.Title); } CommandLine.PressAnyKeyToExit(); }
public static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Tasks API"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new TasksService(auth); // Execute request: Create sample list. if (!ListExists(service, SampleListName) && CommandLine.RequestUserChoice("Do you want to create a sample list?")) { CreateSampleTasklist(service); } CommandLine.WriteLine(); // Execute request: List task-lists. ListTaskLists(service); CommandLine.PressAnyKeyToExit(); }
static void Main(string[] args) { CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("YouTube Data API: My Uploads"); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifier = credentials.ClientId, ClientSecret = credentials.ClientSecret }; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); var youtube = new YoutubeService(new BaseClientService.Initializer() { Authenticator = auth }); var channelsListRequest = youtube.Channels.List("contentDetails"); channelsListRequest.Mine = true; var channelsListResponse = channelsListRequest.Fetch(); foreach (var channel in channelsListResponse.Items) { var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads; CommandLine.WriteLine(String.Format("Videos in list {0}", uploadsListId)); var nextPageToken = ""; while (nextPageToken != null) { var playlistItemsListRequest = youtube.PlaylistItems.List("snippet"); playlistItemsListRequest.PlaylistId = uploadsListId; playlistItemsListRequest.MaxResults = 50; playlistItemsListRequest.PageToken = nextPageToken; var playlistItemsListResponse = playlistItemsListRequest.Fetch(); foreach (var playlistItem in playlistItemsListResponse.Items) { CommandLine.WriteLine(String.Format("{0} ({1})", playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId)); } nextPageToken = playlistItemsListResponse.NextPageToken; } } CommandLine.PressAnyKeyToExit(); }
static void Main(string[] args) { // Initialize this sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("URLShortener -- List URLs"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); // Create the service. var service = new UrlshortenerService(auth); // List all shortened URLs: CommandLine.WriteAction("Retrieving list of shortened urls..."); int i = 0; string nextPageToken = null; do { // Create and execute the request. var request = service.Url.List(); request.StartToken = nextPageToken; UrlHistory result = request.Fetch(); // List all items on this page. if (result.Items != null) { foreach (Url item in result.Items) { CommandLine.WriteResult((++i) + ".) URL", item.Id + " -> " + item.LongUrl); } } // Continue with the next page nextPageToken = result.NextPageToken; } while (!string.IsNullOrEmpty(nextPageToken)); if (i == 0) { CommandLine.WriteAction("You don't have any shortened URLs! Visit http://goo.gl and create some."); } // ... and we are done. CommandLine.PressAnyKeyToExit(); }
static void Main(string[] args) { CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("YouTube Data API: Upload Video"); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifier = credentials.ClientId, ClientSecret = credentials.ClientSecret }; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); var youtube = new YoutubeService(new BaseClientService.Initializer() { Authenticator = auth }); var video = new Video(); video.Snippet = new VideoSnippet(); video.Snippet.Title = CommandLine.RequestUserInput <string>("Video title"); video.Snippet.Description = CommandLine.RequestUserInput <string>("Video description"); video.Snippet.Tags = new string[] { "tag1", "tag2" }; video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list video.Status = new VideoStatus(); video.Status.PrivacyStatus = CommandLine.RequestUserInput <string>("Video privacy (public, private, or unlisted)"); var filePath = CommandLine.RequestUserInput <string>("Path to local video file"); var fileStream = new FileStream(filePath, FileMode.Open); var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*"); videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived; var uploadThread = new Thread(() => videosInsertRequest.Upload()); uploadThread.Start(); uploadThread.Join(); CommandLine.PressAnyKeyToExit(); }
static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("Site Verification sample"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); FullClientCredentials credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new SiteVerificationService(); RunVerification(service); CommandLine.PressAnyKeyToExit(); }
static void Main(string[] args) { CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("YouTube Data API: Playlist Updates"); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description) { ClientIdentifier = credentials.ClientId, ClientSecret = credentials.ClientSecret }; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization); var youtube = new YoutubeService(new BaseClientService.Initializer() { Authenticator = auth }); var newPlaylist = new Playlist(); newPlaylist.Snippet = new PlaylistSnippet(); newPlaylist.Snippet.Title = "Test Playlist"; newPlaylist.Snippet.Description = "A playlist created with the YouTube API v3"; newPlaylist.Status = new PlaylistStatus(); newPlaylist.Status.PrivacyStatus = "public"; newPlaylist = youtube.Playlists.Insert(newPlaylist, "snippet,status").Fetch(); var newPlaylistItem = new PlaylistItem(); newPlaylistItem.Snippet = new PlaylistItemSnippet(); newPlaylistItem.Snippet.PlaylistId = newPlaylist.Id; newPlaylistItem.Snippet.ResourceId = new ResourceId(); newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video"; newPlaylistItem.Snippet.ResourceId.VideoId = "GNRMeaz6QRI"; newPlaylistItem = youtube.PlaylistItems.Insert(newPlaylistItem, "snippet").Fetch(); CommandLine.WriteLine(String.Format("Playlist item id {0} was added to playlist id {1}.", newPlaylistItem.Id, newPlaylist.Id)); CommandLine.PressAnyKeyToExit(); }