Hi

I am hoping someone can help me simply read a spreadsheet using a Service 
Account. I have followed the available documentation to the letter but I am 
still getting an Unathorized response when trying to read the spreadsheet. 
To note that it works fine when I provide 
the SpreadsheetsService.setUserCredentials(myusername,mypassword) but when 
I try use OAuth2 it fails. Here are my steps:

1. I set up the certificate and create a credential variable as below. This 
all works fine

Dim certificate As New X509Certificate2(_p12Path, _p12pwd, 
X509KeyStorageFlags.Exportable)

Dim credential As New ServiceAccountCredential(New 
ServiceAccountCredential.Initializer(_serviceAccountEmail) With {
                                         .Scopes = scopes
                                        }.FromCertificate(certificate))

2. I then request a Token. Again this works fine as well. The 'key' 
variable contains a long string of characters which i assume is the key 
coming from Google.

 Dim key As String = ""

  If 
credential.RequestAccessTokenAsync(Threading.CancellationToken.None).Result 
= True Then
                    key = credential.Token.AccessToken
               
 End If

3. I then set the authentication token by calling 
the SetAuthenticationToken on the SpreadsheetsService class

 Result = New SpreadsheetsService("Godochurch")
                Result.SetAuthenticationToken(key)

4. Finally i set up the spreadsheet qry and execute the query:

 Dim qry As New SpreadsheetQuery
        qry.Title = "Spreadsheet title"
        qry.Exact = True



        Dim feed As SpreadsheetFeed = MyService.Query(qry)


I Keep getting an Unauthorized error. In the body of the errors it tells me 
my Token in Invalid.

Any ideas where I am going wrong?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to