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 = "[email protected]"

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

0
0
Awgiedawgie 104555 points

                                    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

0
0
Are there any code examples left?
Create a Free Account
Level up your programming skills with IQCode
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Pleased to see you again

Sign up to unlock all of IQCode features:
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source