简体   繁体   English

协助开始使用 Gmail API

[英]Assistance with starting off with the Gmail API

我需要有关如何开始使用 google api 以及如何制作我的第一个正常运行的 gmail 应用程序(在 c# 中)的帮助

Google has a sample for use with .net and gmail Quick start .net its a good place to start. Google 有一个与 .net 和 gmail 一起使用的示例Quick start .net是一个很好的起点。 This sample is designed however for installed applications.但是,此示例是为已安装的应用程序设计的。

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);

If your working iwht a web app then you will need to follow the authorizatonm from this sample .如果您使用的是网络应用程序,那么您将需要遵循此示例中的授权。 As there is a web auth and installed auth are diffrent因为有一个网络身份验证和安装的身份验证是不同的

public void ConfigureServices(IServiceCollection services)
{
    ...

    // This configures Google.Apis.Auth.AspNetCore3 for use in this app.
    services
        .AddAuthentication(o =>
        {
            // This forces challenge results to be handled by Google OpenID Handler, so there's no
            // need to add an AccountController that emits challenges for Login.
            o.DefaultChallengeScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
            // This forces forbid results to be handled by Google OpenID Handler, which checks if
            // extra scopes are required and does automatic incremental auth.
            o.DefaultForbidScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
            // Default scheme that will handle everything else.
            // Once a user is authenticated, the OAuth2 token info is stored in cookies.
            o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        })
        .AddCookie()
        .AddGoogleOpenIdConnect(options =>
        {
            options.ClientId = {YOUR_CLIENT_ID};
            options.ClientSecret = {YOUR_CLIENT_SECRET};
        });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM