我有一个经过适当授权的 YouTubeService,可用于检索“已登录”用户的视频列表。我的问题是我不知道如何过滤掉响应,这样我就可以降低我对配额限制的消耗。此外,我只需要了解视频的一些细节。这是我得到的:
私有静态 Google.Apis.Youtube.v3.YoutubeService _youtubeService;
公共静态无效GetList(字符串ID){
var response = _youtubeService.Videos.List(id, "snippet");
// 一些处理在这里发生
}
我想使用此处描述的 fields 参数包含一个过滤器。我只想获取以下字段:Snippet 及其标题和缩略图,并且有效地包含:fields=items(id,snippet(title,thumbnails(value)))在我的请求中。
我怎样才能做到这一点?
我编写了一个 ASP.NET Core Web 应用程序,它使用 Auth0 作为用户的主要授权机制,它中间人是一大堆外部身份验证端点,例如 Google 和 Facebook。这工作得很好,我在那里没有任何问题。
该网络应用程序的核心利用 Google Analytics 来执行自己的分析和业务逻辑。我的网络应用程序正在分析的 Google Analytics 帐户可能并且很可能与用户自己的 Google 帐户不同。需要明确的是,我的意思是,用户很可能会使用他们希望的任何登录提供商登录,然后他们将附加一个特定的 Google 企业帐户,可以访问其企业的 Google Analytics 系统。
Web 应用程序在用户登录和离线时执行分析。
因此,我始终将用户身份验证 (Auth0) 步骤与 Analytics 帐户步骤的身份验证分开。大致流程如下:
之前我也通过 Auth0 推送 Analytics 身份验证,并且使用缓存的 Auth0 刷新令牌来离线工作。然而,它会在几天后过期,并且 Auth0 似乎不提供长期离线访问。
因此,我认为最简单的方法就是不使用 auth0 进行 Analytics 身份验证步骤,直接使用 Google API 进行身份验证并长期存储 Google 刷新令牌。但是我找不到任何具体的例子来说明如何实现这一目标!
c# google-api google-api-dotnet-client asp.net-core-mvc auth0
我需要访问一些 Google API(通过Google.Apis.*NuGet 包)。因此我需要按照官方文档Google.Apis.Auth.AspNetCore中的描述使用该包
:
services
.AddAuthentication(o =>
{
o.DefaultChallengeScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
o.DefaultForbidScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddGoogleOpenIdConnect(options =>
{
options.ClientId = googleClientId;
options.ClientSecret = googleClientSecret;
});
Run Code Online (Sandbox Code Playgroud)
另一方面,我使用经典的 ASP.NET Core Identity,特别是
使用
NuGet 包的Google 外部登录设置Microsoft.AspNetCore.Authentication.Google,其初始化如下:
services
.AddAuthentication()
.AddGoogle(options =>
{
options.ClientId = googleClientId;
options.ClientSecret = googleClientSecret;
});
Run Code Online (Sandbox Code Playgroud)
有没有办法共享 OAuth 配置、登录……?这两个包都使用自己的 OAuth 初始化代码...我在调用 和 时会遇到问题AddGoogle()吗AddGoogleOpenIdConnect()?
c# google-api google-oauth google-api-dotnet-client asp.net-core
C#Google API文档在哪里?
样本代码在哪里?
这些已经过时了.
https://developers.google.com/gdata/client-cs https://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg/Calendar.VB. ConsoleApp
该网站上还有未解答的类似问题.
c# google-authentication google-api-client google-api-dotnet-client
我想使用OAuth使用Google AnalyticsAPI.
我正在使用此库:http: //code.google.com/p/google-api-dotnet-client/
以下代码用于身份验证:
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets { ClientId = "...", ClientSecret = "..." },
new[] {Google.Apis.Analytics.v3.AnalyticsService.Scope.AnalyticsReadonly},
"user",
CancellationToken.None,
new FileDataStore("Analytics.Auth.Store")).Result;
var service = new Google.Apis.Analytics.v3.AnalyticsService(
new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "...",
});
Run Code Online (Sandbox Code Playgroud)
我可以将它与refresh_token一起使用,这样我就不必每隔几天就接受一次授权请求吗?
类似于这个问题的答案: 服务帐户Google Analytics OAuth AccessType =离线C#
我正在使用适用于 OAuth2 1.9 版的 Google API,并尝试每次将 AccessType 作为离线发送和 ApprovalPrompt 作为强制发送,以便我获得刷新令牌。我知道这里有很多关于这个主题的问题,有各种 api 版本和语言。但是,没有一个解决方案适用于新的 google 库。
我正在使用以下内容来获取流程:
private IAuthorizationCodeFlow GetAuthorizationCodeFlow()
{
var flow = new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId =
"***",
ClientSecret = "***"
},
Scopes = new string[]
{
CalendarService.Scope.Calendar,
PlusService.Scope.UserinfoProfile,
PlusService.Scope.UserinfoEmail,
PlusService.Scope.PlusLogin,
"https://www.googleapis.com/auth/contacts.readonly"
}
});
return flow;
}
Run Code Online (Sandbox Code Playgroud)
然后使用以下代码获取令牌:
var token = flow.ExchangeCodeForTokenAsync("me", code,
uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result;
Run Code Online (Sandbox Code Playgroud)
这是我每次(不仅仅是第一次)都需要刷新令牌的地方,所以我想设置 AccessType 和 ApprovalPrompt。
我试试这段代码:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web_applications
我的代码一样
但!我需要更改此默认网址重定向.现在是:redirect_uri = http:%2F%2Flocalhost:52674%2FAuthCallback%2FIndexAsync
我怎么能改变这个网址?伙计们请帮忙.
谢谢
我正在根据这个Google示例代码开发一个Asp.NET MVC5应用程序.
我希望应用程序经过身份验证并由用户创建一个accessstoken(配置阶段),之后我需要能够使用刷新令牌调用Google APis(在我的情况下为Directory API)(无需用户干预,例如"离线").
控制器:
public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)
{
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var service = new Google.Apis.Admin.Directory.directory_v1.DirectoryService(new BaseClientService.Initializer
{
HttpClientInitializer = result.Credential,
ApplicationName = "My Application"
});
return View();
}
else
{
return new RedirectResult(result.RedirectUri);
}
}
Run Code Online (Sandbox Code Playgroud)
FlowMetadata实现.(我使用FiledataStore稍加修改(GoogleFileDataStore))
public class AppFlowMetadata : FlowMetadata
{
//Move to settings
static readonly string clientId = "xxxccnvofsdfsfoj.apps.googleusercontent.com";
static readonly string clientsecret = "xxxxxxxxxxLvtC6Qbqpp4x_";
static readonly string …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个基本的C#应用程序来在我使用Google.Apis.Pagespeedonline.v2 nuget包指定的网站上运行PageSpeed测试.
设置很简单,我有一个变量,我可以指定url,然后进入服务
// Create the service.
var service = new PagespeedonlineService(new BaseClientService.Initializer
{
ApplicationName = "PageSpeed Sample",
ApiKey = "[API_KEY_HERE]"
});
var url = "URL_TO_TEST";
// Run the request.
var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();
Run Code Online (Sandbox Code Playgroud)
问题是.Runpagespeed方法只接受URL.我需要能够至少指定"移动"策略,这样我才能获得桌面和移动设备的分数.我知道这在其他库中是可行的,但在.NET中似乎缺失了.有人知道使用.NET库的方法吗?在参考文档中,它暗示该方法接受更多可选参数,但它不在代码中.
c# asp.net pagespeed google-pagespeed google-api-dotnet-client
我制作了一个程序,使用谷歌驱动器API从谷歌驱动器上的文件中读取数据.
第一次运行应用程序时,它会打开一个Web浏览器,要求使用google驱动器帐户登录.
我想为应用程序提供用户名和密码,以便自动获取凭据,以便用户无需知道我的google云端硬盘帐户的用户名和密码.
这是vb.net中的代码:
Dim credential As UserCredential
Using stream = New FileStream("client_secret.json", FileMode.Open, FileAccess.Read)
Dim credPath As String = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal)
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json")
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
New FileDataStore(credPath, True)).Result
'Console.WriteLine("Credential file saved to: " + credPath)
End Using
//I want to provide the username and password in the app so that it doesn't open a web browser asking for them
' Create Drive API service.
Dim initializer = New BaseClientService.Initializer
initializer.HttpClientInitializer = credential …Run Code Online (Sandbox Code Playgroud) c# vb.net google-api google-drive-api google-api-dotnet-client
c# ×8
google-api ×5
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
auth0 ×1
google-oauth ×1
oauth-2.0 ×1
pagespeed ×1
vb.net ×1
youtube-api ×1