简体   繁体   English

自动获取Google API Client_ID和Client_Secret

[英]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.

相关问题 在Oauth2中哪里存储client_id和client_secret? - Where to store client_id and client_secret in Oauth2? 我的OAuth API的client_id / client_secret是否可以用于其他用户? - Will my client_id/client_secret for OAuth API work for other users? Passport.js使用client_id和client_secret做什么用途? - What does Passport.js use the client_id and client_secret for? OAuth 2.0中两足式身份验证中client_id和client_secret的用法是什么 - What is the use of client_id and client_secret in 2-legged Authentication in OAuth 2.0 带有 Client_Id 和 Client_Secret 的 OAuth2 密码授予类型 - OAuth2 Password Grant Type with Client_Id & Client_Secret 如何仅使用客户端ID和客户端密钥对Google Api进行身份验证 - How to Authenticate Google Api using client id and client secret only Hubspot API访问权限,但client_id - hubspot api access but client_id 如何为 IdentityServer4 创建一个 client_secret? - How to create a client_secret for IdentityServer4? Microsoft Graph:如何在客户端凭据流中使用证书获取访问令牌? (而不是使用 client_secret) - Microsoft Graph: How to get access token with certificate in client credentials flow? (instead of using a client_secret) 检索Google客户端ID和客户端密钥Azure身份验证 - Retrieve Google Client ID and Client Secret Azure Authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM