使用VB和Google API在Google日历中创建事件

时间:2018-11-07 18:20:01

标签: vb.net

我在尝试使用VS2015编写VB程序以使用其API在Google日历中创建事件时遇到问题,似乎缺少有关API和VB的信息。我在下面发布了我的整个代码,而我遇到的问题就在网上:-

  

Dim createdEvent作为[Event] = request.Execute(),我得到的错误是   权限不足[403]   错误[       消息[权限不足]位置[-]原因[insufficientPermissions]域[全局]

任何人都可以帮忙

Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Services
Imports Google.Apis.Util.Store
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Threading
Imports System.Threading.Tasks
Imports Google.Apis.Calendar.v3.EventsResource
Imports Google.Apis.Requests


 Public Class Form1

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   SurroundingSub()
 End Sub

 Private Sub SurroundingSub()   
Dim service = Authenticate()
    Dim newEvent As [Event] = New [Event]() With {
    .Summary = "Google I/O 2015",
    .Location = "800 Howard St., San Francisco, CA 94103",
    .Description = "A chance to hear more about Google's developer products.",
    .Start = New EventDateTime() With {
        .DateTime = DateTime.Parse("2015-05-28T09:00:00-07:00"),
        .TimeZone = "America/Los_Angeles"
    },
    .[End] = New EventDateTime() With {
        .DateTime = DateTime.Parse("2015-05-28T17:00:00-07:00"),
        .TimeZone = "America/Los_Angeles"
    },
    .Recurrence = New String() {"RRULE:FREQ=DAILY;COUNT=2"},
    .Attendees = New EventAttendee() {New EventAttendee() With {
        .Email = "mickburden@btinternet.com"
    }, New EventAttendee() With {
        .Email = "mickburden@btinternet.com"
    }},
    .Reminders = New [Event].RemindersData() With {
        .UseDefault = False,
        .[Overrides] = New EventReminder() {New EventReminder() With {
            .Method = "email",
            .Minutes = 24 * 60
        }, New EventReminder() With {
            .Method = "sms",
            .Minutes = 10
        }}
    }
}

    Dim calendarId As String = "primary"
    Dim request As EventsResource.InsertRequest = service.Events.Insert(newEvent, calendarId)
    Dim createdEvent As [Event] = request.Execute()
   End Sub


    Private Function Authenticate()
    Dim scopes = New List(Of String)
    scopes.Add(CalendarService.Scope.Calendar)

    Dim credential As UserCredential
    Using stream As New FileStream("credentials.json", FileMode.Open, FileAccess.Read)
        '     Using stream As New FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None,
                New FileDataStore("Calendar.VB.Sample")).Result
    End Using

    Dim initializer As New BaseClientService.Initializer()
    initializer.HttpClientInitializer = credential
    initializer.ApplicationName = "VB.NET Calendar Sample"
    Dim service
    service = New CalendarService(initializer)
    Return service
    End Function 

end class

0 个答案:

没有答案