2014-09-21 1 views
0

메신저가 datagridview에서 Gmail 메시지 정보를 가져 오려고 시도하지만 "return nothing"행을 지운 경우에도 비어있는 Dataagridview 만 반환하지만 시도 할 때 apis-explorer에서 나는 200 OK 응답을 얻는다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?Gmail api v1 (인터넷)의 "Get"메시지와 관련된 문제

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, "[email protected]", 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 
+0

어떤 전화를받을 수 있습니까? labels.list()와 같이 사소한 것을 말해봐? 나는 그것이 예외를 던지지 않고 있다고 추정한다? 그렇다면 출력 한 전체 응답 (HTTP 헤더 및 본문)을 포함시켜주십시오. –

답변

-1

감사 에릭하지만 난 이미 몇 가지 변경을 해결 :

임 사용하는 코드는 구글 개발자 문서에서입니다. 구글 개발자 문서가 너무 명확하지 않기 때문에 다른 사람들에게 도움이되기를 바랍니다.

Imports Google.Apis.Auth.OAuth2 
Imports Google.Apis.Services 
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 
     Try 
      scope.Add(GmailService.Scope.MailGoogleCom) 
      Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scope, "[email protected]", CancellationToken.None).Result() 
      initializer.HttpClientInitializer = credential 
      initializer.ApplicationName = "APP NAME" 
      Dim service = New GmailService(initializer) 
      Dim userId As String = "EMAIL" 
      Dim messageId As String = "MESSAGE ID" 

      Me.DataGridView1.DataSource = GetMessage(service, userId, messageId).Payload.Headers 
      TextBox1.Text = (GetMessage(service, userId, messageId).Snippet)   
     Catch ex As Exception 
      MsgBox(ex.ToString) 
     End Try 
    End Sub 
End Class 
+0

새로운 코드 세그먼트를 게시하는 대신 원래 버그를 요약 할 수 있습니까? –

+0

죄송합니다, api에 새로운 기능이 있습니다. 나는 그 버그가 원래 무엇인지 알지 못한다. 단지 "희미한 userId"와 "dim messageId"를 다른 곳에 두었다가 코드가 완벽하게 작동한다. –

+0

.NET에서는 익숙하지 않지만 변수 선언을 "희미하게 ..."이동하면 try 블록 외부에서 변수가 변경 될 가능성이 매우 낮아 보입니다. 문제는 다른 곳에서. –