Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Get Youtube streaming via Google authentication with service account

$
0
0
private YouTubeService _youtubeService;private UserCredential _credential;using (var stream = new FileStream(JsonSavePath, FileMode.Open, FileAccess.Read)){    _credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(                    //GoogleClientSecrets.Load(stream).Secrets,                    GoogleClientSecrets.FromStream(stream).Secrets,                    // This OAuth 2.0 access scope allows for full read/write access to the                    // authenticated user's account.                    new[] { YouTubeService.Scope.Youtube },"user",                    CancellationToken.None,                    new FileDataStore(this.GetType().ToString())                );            }            _youtubeService = new YouTubeService(new BaseClientService.Initializer()            {                HttpClientInitializer = _credential,                ApplicationName = this.GetType().ToString()            });

I have already authenticated via GoogleWebAuthorizationBroker for credentials and for youtube service YouTubeService also with the help you oAuth.V2 (But this is a console app so that I should athenticate these authorization for youtube streaming with out UI access).

The Question is how can we write these functionality via service account.

I have also create service account in google console app and also added {wide-domain delegation scope} against google service client account.

Also get the token in class so I need to write same call for google credentials and youtube credentials in my service class.

public void GetTokenAndCall()    {        var token = GoogleServiceAccount.GetAccessTokenFromJSONKey(JsonKeyFilePath, "https://www.googleapis.com/auth/userinfo.profile");        Console.WriteLine(new HttpClient().GetStringAsync($"https://www.googleapis.com/plus/v1/people/110259743757395873050?access_token={token}").Result);     }

This is my service account authentication and I can get the token Id but how can I make a call for youtube service _youtubeService and google authentication _credential without oAuthv2 like without UI authorization I want to authorize my app user.

enter image description here

You can see the attachment for the token.

Kindly help me to write _credential & _youtubeService call in my service account method GetTokenAndCall();

Note: I can't use my previous _credential & _youtubeService Calls because of Ui authorization, so I decided to authorize via service account, help me to write the same call in my GetTokenAndCall() via service structure so that I show my youtube streaming to my console app.I want server-to-server authentication.


Viewing all articles
Browse latest Browse all 3831

Trending Articles