谷歌Analytics(分析)的OAuth与接入类型=脱机在C# [英] Google Analytics OAuth with AccessType = Offline in C#
问题描述
我想使用OAuth使用谷歌Analytics(分析)API。
I want to use Google Analytics API using OAuth.
我使用这个库:
HTTP://$c$c.google.com/p/谷歌的API-DOTNET的客户端/
以下code用于身份验证:
The following code is used for authentication:
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 = "...",
});
我可以用这一个refresh_token,这样我就不必接受授权请求每隔几天?
Can I use this with a refresh_token so that I do not have to accept the authorization request every few days?
喜欢的东西在这个问题的答案:
<一href=\"http://stackoverflow.com/questions/9366380/service-account-google-analytics-oauth-accesstype-offline-c-sharp\">Service占谷歌分析OAuth的接入类型=脱机C#
Something like in the answer of this question: Service Account Google Analytics OAuth AccessType = Offline C#
推荐答案
我知道,只有一个办法:你需要重写 GoogleAuthorization codeRequestUrl
,但我没有知道如何使用 AuthorizationBroker
使用。
I know only one way: you need to override GoogleAuthorizationCodeRequestUrl
, but I have no idea how to use this with AuthorizationBroker
.
internal class ForceOfflineGoogleAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
public ForceOfflineGoogleAuthorizationCodeFlow(AuthorizationCodeFlow.Initializer initializer) : base(initializer) { }
public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
{
return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
{
ClientId = ClientSecrets.ClientId,
Scope = string.Join(" ", Scopes),
RedirectUri = redirectUri,
AccessType = "offline",
ApprovalPrompt = "force"
};
}
};
看起来他们创造流动券商里面:
<一href=\"https://$c$c.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.Auth.WP/OAuth2/GoogleWebAuthorizationBroker.cs?r=e6585033994bfb3a24d4c140db834cb14b9738b2\">GoogleWebAuthorizationBroker.cs
和我没有看到任何的方式来传递PARAMS或更换授权codeFLOW
And I didn't see any way to pass params or replace AuthorizationCodeFlow
这篇关于谷歌Analytics(分析)的OAuth与接入类型=脱机在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!