Im trying to get info of a gmail message in a datagridview but only returns the datagridview empty (even when I erase the "return nothing" line) but when I try in apis-explorer I get the 200 ok response. What am I doing wrong?
The code Im using is from the google developers documentation:
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports Google.Apis.Tasks.v1
Imports Google.Apis.Tasks.v1.Data.Tasks
Imports Google.Apis.Tasks.v1.Data
Imports System.Collections.Generic
Imports Google.Apis.Util.Store
Imports System.Threading
Imports System
Imports Google.Apis.Gmail.v1
Imports Google.Apis.Gmail.v1.Data
Public Class Form1
Dim Secrets = New ClientSecrets()
Dim scope = New List(Of String)
Dim initializer = New BaseClientService.Initializer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Secrets.ClientId = "CLIENT_ID"
Secrets.ClientSecret = "CLIENT_SECRET"
End Sub
Public Shared Function GetMessage(service As GmailService, userId As [String], messageId As [String]) As Message
Try
Return service.Users.Messages.Get(userId, messageId).Execute()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'Return Nothing
End Function
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
Dim userId As String = "GMAIL ACCOUNT"
Dim messageId As String = "MESSAGE ID"
Try
scope.Add(GmailService.Scope.MailGoogleCom)
Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scope, "XXXXXXXXXXXX@developer.gserviceaccount.google.com", CancellationToken.None).Result()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "APP NAME"
Dim service = New GmailService(initializer)
Me.DataGridView1.DataSource = GetMessage(service, userId, messageId)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class