[英]Get Google API Client_ID and Client_Secret automatically
I'am currently working on my C# program that sync my Outlook-Calendar-Events to my Google-Calendar. 我目前正在使用C#程序,它将Outlook-Calendar-Events同步到我的Google-Calendar。 To get connected to my Google calendar I need my Client-ID and my Client-Secret. 要连接到我的Google日历,我需要我的客户ID和我的客户秘密。 At the moment I have to write my data manually to my C# code but thats quite annoying. 目前,我必须将数据手动写入C#代码,但这很烦人。 Are there any possibilities to get the Google API Client-ID and the Client-Secret with the first login so I don't have to write them manually to my code? 是否可以通过首次登录获取Google API的Client-ID和Client-Secret,所以我不必手动将它们写入我的代码中?
This is how my current function looks like to get authenticated: 这是我当前的函数通过身份验证的样子:
public CalendarService authentication()
{
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = MY_CLIENT_ID,
ClientSecret = MY_CLIENT_SECRET,
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential
});
return service;
}
Unfortunately, I don't think there is a way to automatically generate the client ID and secret. 不幸的是,我认为没有一种方法可以自动生成客户端ID和密码。 Since, this is something that is private to your application. 因为,这是您的应用程序专用的。 The only way to generate the Google client ID and secret is through the Google Developer console . 生成Google客户端ID和机密的唯一方法是通过Google Developer Console 。
However, the only one you can automatically generate is the access token since this is short-lived. 但是,您可以自动生成的唯一令牌是访问令牌,因为这是短暂的。 To do this, you would need to have the refresh token of the user (assuming the user is authenticated and approves). 为此,您需要具有用户的刷新令牌(假设用户已通过身份验证并获得批准)。 Hope this helps and Good luck. 希望这会有所帮助,祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.