/// <summary> /// Create a service connection to google. /// </summary> /// <param name="userEmail">The API email to use for authentication.</param> /// <param name="gService">The type of service to connect to.</param> /// <returns>Returns an open connection to the google api service, or null.</returns> private static BaseClientService BuildService(string userEmail, GoogleServices gService = GoogleServices.Directory) { X509Certificate2 certificate = new X509Certificate2(Properties.Resources.gsd_api,"notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL) { Scopes = Scopes, User = userEmail }.FromCertificate(certificate)); switch (gService) { case GoogleServices.Directory: DirectoryService directoryService = new DirectoryService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "GSD GAMS", }); return directoryService; case GoogleServices.Drive: DriveService driveService = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "GSD GAMS", }); return driveService; } return null; }
/// <summary> /// Initializes a new instance of the <see cref="GoogleViewModel"/> class. /// </summary> public GoogleViewModel() { this.googleServices = new GoogleServices(); }
public PlaylistCards(bool userPlaylist, bool userPlaylistContainerParent, string playlistName, PlaylistListResponse userPlaylistResponse, PlaylistItemListResponse playlistItemListResponse, TextBlock songLabel, Rectangle backgroundRectangle, ChromiumWebBrowser youtubePlayer, Grid expandedPlaylistHolder, UserPlaylistsContainer userPlaylistsContainer, ScrollViewer playlistScrollViewer, Button playButton) { InitializeComponent(); Overlay.Opacity = 0; _playlistItemListResponse = playlistItemListResponse; _isUserPlaylist = userPlaylist; _playlistScrollViewer = playlistScrollViewer; _playButton = playButton; if (userPlaylistContainerParent) { UserPlaylistsContainer = userPlaylistsContainer; } if (userPlaylist) { _userPlaylists = userPlaylistResponse; Console.WriteLine(_userPlaylists); //create user image ImageBrush userImageBrush; if (!File.Exists(FilePaths.UserImageLocation + "\\Userimage.png")) { userImageBrush = new ImageBrush(new BitmapImage(new Uri(GoogleServices.GetUserPicture()))); } else { userImageBrush = new ImageBrush(new BitmapImage(new Uri(FilePaths.UserImageLocation + "\\Userimage.png"))); } userImageBrush.TileMode = TileMode.None; UserPlaylistCover.Fill = userImageBrush; PlaylistName.Text = "Your Playlists"; Panel.SetZIndex(SearchedPlaylistImagesCover, -9999); if (_userPlaylists.Items != null) { ChannelName.Content = _userPlaylists.Items[0].Snippet.ChannelTitle; } else { ChannelName.Content = GoogleServices.UserPerson.DisplayName; } UserPlaylistsContainer = new UserPlaylistsContainer(this, _playlistScrollViewer); } else { int thumbnailsAdded = 0, actualIndex = 0; while (true) { Uri backgroundImageUri; try { backgroundImageUri = new Uri(_playlistItemListResponse.Items[actualIndex].Snippet.Thumbnails.Medium.Url); ImageSource tempSource = new BitmapImage(backgroundImageUri); ((Image)SearchedPlaylistImagesCover.Children[thumbnailsAdded]).Source = tempSource; thumbnailsAdded++; actualIndex++; if (thumbnailsAdded == 4) { break; } } catch (Exception e) { Console.WriteLine("Adding song failed " + e); if (thumbnailsAdded != 0) { thumbnailsAdded--; } actualIndex++; } } Panel.SetZIndex(UserPlaylistCover, -9999); ChannelName.Content = playlistItemListResponse.Items[0].Snippet.ChannelTitle; PlaylistName.Text = playlistName; } Panel.SetZIndex(this, 1); _songLabel = songLabel; _playlistName = playlistName; _backgroundRectangle = backgroundRectangle; _youtubePlayer = youtubePlayer; _expandedPlaylistHolder = expandedPlaylistHolder; _isUserPlaylist = userPlaylist; }
public static async void ProcessGoogleLogin(string code) { await GoogleServices.GetUserProfile(code); }
/* * Launches Google authentication and attempts to switch the * login method for the the logged in user. */ void Handle_GoogleAccountTypeTapped(object sender, System.EventArgs e) { // Opens the Google login Device.OpenUri(new Uri(GoogleServices.ChangeToGoogleLoginAddr())); updateButtons(); }