我正在做一些基于Web的应用程序,显示数据库条目中的用户日历。在此Web应用程序中,用户可以通过JavaScript库对其Google日历帐户进行身份验证。然后我想与我的桌面服务共享此访问权限。桌面服务是用C#编写的。如何在Google API中使用Web应用程序生成的令牌填充本机应用程序凭据?
是否有人知道如何在C#中填充CalendarService类,并拥有以下代码?
的Javascript:
function auth() {
var config = {
'client_id': "myID",
'scope': "https://www.googleapis.com/auth/calendar"
};
gapi.auth.authorize(config, function() {
console.log('login complete');
console.log(gapi.auth.getToken());
});
}
那么在Windows服务
var tokenResponse = new TokenResponse
{
AccessToken = tokenCopiedFromJavascriptObject,
Issued = propertyCopiedFromJavascriptObject,
TokenType = "Bearer",
Scope = CalendarService.Scope.Calendar,
RefreshToken = "3600"
};
var authorizationCodeFlowInitializer = new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets()
{
ClientId = myIdForDesktopApp,
ClientSecret = ClientSecretForDestopApp
},
Scopes = new[] { CalendarService.Scope.Calendar },
Clock = Google.Apis.Util.SystemClock.Default
};
var authorizationCodeFlow = new GoogleAuthorizationCodeFlow(authorizationCodeFlowInitializer);
_credentials = new UserCredential(authorizationCodeFlow, _calendarId, tokenResponse);
_service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credentials,
ApplicationName = "Fast and Easy Reservation System"
});
const string meeting = "Some fancy meeting";
var e = _service.Events.QuickAdd("primary", meeting).Execute();
}
我的C#代码是否有希望得到这个工作?例如,我在Google API项目中有2个应用程序(网页和桌面)。这些都在一个项目中,所以我认为它应该作为一个混合应用程序工作,他们应该共享一个授权令牌。通过JS AUTH函数返回
对象具有以下属性: 的access_token CLIENT_ID expires_at expires_in issued_at RESPONSE_TYPE 范围 token_type