无法授权未经验证的应用程序
Cant authorize unverified application
我在我的项目中添加了 credentials.json。我写了一些必须在我的日历中创建新事件的代码。当我 运行 我的代码时,我还检查了我的 Google 日历,但我发现没有必须由我的代码创建的新事件。我也没有在 bin/debug 文件夹中看到 token.json。我该如何解决这个问题?
P.S我用同一个账号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Highsoft.Web.Mvc.Charts;
using Highsoft.Web.Mvc.Charts.Rendering;
namespace Kyrsovoi
{
public partial class Form1 : Form
{
static string[] Scopes = { CalendarService.Scope.Calendar };
static string ApplicationName = "Google Calendar API .NET Quickstart";
public Form1()
{
InitializeComponent();
}
private void GoogleAPI()
{
UserCredential credential;
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
// List events.
Events events = request.Execute();
if (events.Items != null && events.Items.Count > 0)
{
foreach (var eventItem in events.Items)
{
string when = eventItem.Start.DateTime.ToString();
if (String.IsNullOrEmpty(when))
{
when = eventItem.Start.Date;
}
Console.WriteLine("{0} ({1})", eventItem.Summary, when);
}
}
else
{
}
var ev = new Event();
EventDateTime start = new EventDateTime();
start.DateTime = new DateTime(2020, 10, 17, 11, 0, 0);
EventDateTime end = new EventDateTime();
end.DateTime = new DateTime(2020, 10, 17, 11, 30, 0);
ev.Start = start;
ev.End = end;
ev.Summary = "MyEvent";
ev.Description = "TestScription";
var calendarId = "primary";
Event recurringEvent = service.Events.Insert(ev, calendarId).Execute();
Console.WriteLine("Event created: %s\n", ev.HtmlLink);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form3 newForm1 = new Form3();
newForm1.Show();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
当您有一个正在测试的应用程序时,它尚未经过验证。您将看到以下屏幕。
按高级
如果按 高级 按钮,您将看到以下内容
授权应用。
这会让您授权一个未经验证的应用程序。
我在我的项目中添加了 credentials.json。我写了一些必须在我的日历中创建新事件的代码。当我 运行 我的代码时,我还检查了我的 Google 日历,但我发现没有必须由我的代码创建的新事件。我也没有在 bin/debug 文件夹中看到 token.json。我该如何解决这个问题? P.S我用同一个账号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Highsoft.Web.Mvc.Charts;
using Highsoft.Web.Mvc.Charts.Rendering;
namespace Kyrsovoi
{
public partial class Form1 : Form
{
static string[] Scopes = { CalendarService.Scope.Calendar };
static string ApplicationName = "Google Calendar API .NET Quickstart";
public Form1()
{
InitializeComponent();
}
private void GoogleAPI()
{
UserCredential credential;
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
// List events.
Events events = request.Execute();
if (events.Items != null && events.Items.Count > 0)
{
foreach (var eventItem in events.Items)
{
string when = eventItem.Start.DateTime.ToString();
if (String.IsNullOrEmpty(when))
{
when = eventItem.Start.Date;
}
Console.WriteLine("{0} ({1})", eventItem.Summary, when);
}
}
else
{
}
var ev = new Event();
EventDateTime start = new EventDateTime();
start.DateTime = new DateTime(2020, 10, 17, 11, 0, 0);
EventDateTime end = new EventDateTime();
end.DateTime = new DateTime(2020, 10, 17, 11, 30, 0);
ev.Start = start;
ev.End = end;
ev.Summary = "MyEvent";
ev.Description = "TestScription";
var calendarId = "primary";
Event recurringEvent = service.Events.Insert(ev, calendarId).Execute();
Console.WriteLine("Event created: %s\n", ev.HtmlLink);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form3 newForm1 = new Form3();
newForm1.Show();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
当您有一个正在测试的应用程序时,它尚未经过验证。您将看到以下屏幕。
按高级
如果按 高级 按钮,您将看到以下内容
授权应用。
这会让您授权一个未经验证的应用程序。