, , IIS Visual Studio Dev Server. , , , , , .
:
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.Auth.OAuth2.Web;
using Google.Apis.Services;
using Google.Apis.YouTube.v3.Data;
using System.Threading;
private void GetData()
{
IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets { ClientId = "[ClientID]", ClientSecret = "[ClientSecret]" },
DataStore = new FileDataStore("C:\\Temp", true),
Scopes = new[] { YouTubeService.Scope.YoutubeReadonly }
});
var userId = "[ACCOUNTNAME]";
var uri = Request.Url.ToString();
var code = Request["code"];
if (code != null)
{
var token = flow.ExchangeCodeForTokenAsync(userId, code, uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result;
var oauthState = AuthWebUtility.ExtracRedirectFromState(flow.DataStore, userId, Request["state"]).Result;
Response.Redirect(oauthState);
}
else
{
var result = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(userId, CancellationToken.None).Result;
if (result.RedirectUri != null)
{
Response.Redirect(result.RedirectUri);
}
else
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer
{
ApplicationName = "MyVideoApp",
HttpClientInitializer = result.Credential
});
if (youtubeService != null)
{
var channelsListRequest = youtubeService.Channels.List("contentDetails");
channelsListRequest.Mine = true;
ChannelListResponse channelsListResponse = channelsListRequest.ExecuteAsync().Result;
foreach (var channel in channelsListResponse.Items)
{
var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet, status");
playlistItemsListRequest.PlaylistId = channel.ContentDetails.RelatedPlaylists.Uploads;
var playlistItemsListResponse = playlistItemsListRequest.ExecuteAsync().Result;
}
}
}
}
}
Google, . URL- http://Console.developers.google.com.
Url API Auth > Credentials. " " URI , :
http://localhost:1234/Default.aspx
http://localhost:1234/Options.aspx