CodeBeam.GoogleApis.Blazor 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeBeam.GoogleApis.Blazor --version 0.0.1
NuGet\Install-Package CodeBeam.GoogleApis.Blazor -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeBeam.GoogleApis.Blazor" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeBeam.GoogleApis.Blazor --version 0.0.1
#r "nuget: CodeBeam.GoogleApis.Blazor, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CodeBeam.GoogleApis.Blazor as a Cake Addin
#addin nuget:?package=CodeBeam.GoogleApis.Blazor&version=0.0.1

// Install CodeBeam.GoogleApis.Blazor as a Cake Tool
#tool nuget:?package=CodeBeam.GoogleApis.Blazor&version=0.0.1

CodeBeam.GoogleApis.Blazor

An open-source utility package for GoogleApis in Blazor.

Always aim for the easiest to use.

GitHub Repo stars GitHub last commit Contributors Nuget version Nuget downloads

This repo is still in earlier stage of development, but all completed parts already tested with real world applications.

Documentation

Please look at examples.

Contributing

Welcome to all contributors!

Usage

Preliminary: Set your google account and your project credentials

Nothing special with this package.

Step 1: Inject HttpClientFactory

Add Services into program.cs

builder.Services.AddCodeBeamGoogleApiServices();

For blazor component files

@inject CalendarService CalendarService

For cs files

[Inject] CalendarService CalendarService { get; set; }

Step 2: Implement whatever you want

private void CreateCalendar()
{
    GoogleCalendarListModel googleCalendarListModel = new GoogleCalendarListModel()
    {
        summary = "Test Calendar",
        description = "Created By CodeBeam",
        timeZone = "Europe/Istanbul",
    };
    CalendarService.AddCalendar(googleCalendarListModel);
}

Step 3: null. That's all.

Examples

How To Use Auth Service To Get Permission From a Google Account

Step 1. Request Authorization Code
private async Task RequestCode()
{
    List<Scope> scopes = new();
    scopes.Add(Scope.OAuth2Email); //Not required, but useful for get user email in future.
    scopes.Add(Scope.Calendar);
    await AuthService.RequestAuthorizationCode(AuthService.GetClientId(), scopes, NavigationManager.BaseUri + "v1/browser-callback"); //"v1/browser-callback" is your page that method returns and opens the page as a new tab
}
Step 2. Get Access Token With Obtained Authorization Code in Step 1

These codes should be in the callback page. Blazor Component

@page "/v1/browser-callback"

Code

[Parameter]
[SupplyParameterFromQuery]
public string Code { get; set; }

string _accessToken = "";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        var request = AuthService.AuthorizeCredential(Code, AuthService.GetCliendId(), AuthService.GetClientSecret(), NavigationManager.BaseUri + "v1/browser-callback");
        // This method is built in this package. You also can write your own method to process request result.
        _accessToken = AuthService.GetValueFromCredential(request, CredentialValueType.AccessToken);
    }
}
Step 3. You can store this access token (can also obtain refresh token etc. with same way) in your database or make a cookie. You can use this token to call calendar, drive etc. features.

How To Create a Calendar Event

Make an instance of GoogleCalendarEventModel and add it. Notice that for datetimes like event start and end, need to use GetProperDateTimeFormat method.
[Inject] CalendarService CalendarService { get; set; }
private void AddEvent()
{
    GoogleCalendarEventModel googleCalendarEvent = new()
    {
        summary = "Test Event",
        description = "Some Description",
        start = new Start { dateTime = CalendarService.GetProperDateTimeFormat(DateTime.Now) },
        end = new End { dateTime = CalendarService.GetProperDateTimeFormat(DateTime.Now) },
    };
    // If you don't know the id of calendar which will the event be added, use FindCalendarId method. In this case, the event added the calendar which has "Test Calendar" title.
    string result = CalendarService.AddEvent(googleCalendarEvent, CalendarService.FindCalendarId(CalendarValueType.Summary, "Test Calendar"));
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 698 7/12/2022
0.2.1.1 750 5/18/2022
0.2.0 663 5/14/2022
0.1.0 622 5/13/2022
0.0.1 614 5/10/2022