I need help on how to start off with google apis and how to make my first functioning gmail app (in c#)
Asked
Active
Viewed 53 times
1 Answers
0
Google has a sample for use with .net and gmail Quick start .net its a good place to start. 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};
});
}

Linda Lawton - DaImTo
- 106,405
- 32
- 180
- 449
-
let me know if you have any issues – Linda Lawton - DaImTo Jun 13 '22 at 16:22
-
@DalmTo This sounds really stupid, but how do you get the credentials.json file ? – user18800522 Jun 14 '22 at 02:50
-
I have a video on how to create the json file so this is not stupid a stupid question https://www.youtube.com/watch?v=pBVAyU4pZOU just remember to enable the gmail api under libraries – Linda Lawton - DaImTo Jun 14 '22 at 07:54