mvc authentication token code example

Example 1: token em vbnet incluido no header da requisição

Private Sub ConectaPlanilhaFuncional(scope As String)
        Dim certificate As New X509Certificate2(Server.MapPath("/certificate/key.p12"), "notasecret", X509KeyStorageFlags.Exportable)
        Dim credential = New ServiceAccountCredential(New ServiceAccountCredential.Initializer(service_email) With { _
             .Scopes = New String() {scope}
        }.FromCertificate(certificate))
        Try
            credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait()
        Catch ex As Exception
        End Try
        Dim requestFactory As New GDataRequestFactory(nome_aplicacao)
        requestFactory.CustomHeaders.Add(String.Format("Authorization: Bearer {0}", credential.Token.AccessToken))
        Dim myService As New SpreadsheetsService(nome_aplicacao)
        myService.RequestFactory = requestFactory
        Dim query As New SpreadsheetQuery()
        Dim feed As SpreadsheetFeed = myService.Query(query)     
        For Each f As SpreadsheetEntry In feed.Entries
            Dim texto As String = f.Title.Text        
        Next     
    End Sub

Example 2: token em vbnet incluido no header da requisição

Const client_id = "XXXX.apps.googleusercontent.com"
Const client_secret = "XXXXXXXXXXX"
Const refresh_token = "XXXXXXXXXX"
Const nome_aplicacao = "MinhaAplicacao"
Const user_id = "MeuEmail@gmail.com"

Private Function CriaContactRequest(Optional scope As String = "https://www.google.com/m8/feeds https://www.google.com/m8/feeds/groups/default/full") As ContactsRequest
        Try
            Dim rs = New RequestSettings(nome_aplicacao) With { _
                            .OAuth2Parameters = New OAuth2Parameters() With { _
                            .AccessToken = refresh_token, _
                            .RefreshToken = refresh_token, _
                            .ClientId = client_id, _
                            .ClientSecret = client_secret, _
                            .RedirectUri = redirect_uri, _
                            .Scope = scope _
                        } _
                    }
            Dim cr As New ContactsRequest(rs)
            Return cr
        Catch ex As Exception
            Throw ex
        End Try
    End Function