Hello,

I'm working with dotnet C#, Sheets v4.
I'm the owner of a sheets in Drive, which is shared with some people who 
are internal and external of the company.

We are using service account also with adwords API.
For sheets, we added scope "SheetsService.Scope.SpreadsheetsReadonly" on 
the Google Console Admin

When we are trying to read the sheets with the API, even with my account 
(whereas I'm the owner), we got an exception "*Error:"unauthorized_client", 
Description:"Unauthorized client or scope in request.", Uri:""*

It's working with a public sheets on a personnal drive account, with the 
sharing policy "read access to anyone with the link"


   1. What am I doing wrong?
   2. Can you confirm it's possible to impersonate a user using the User 
   property of the ServiceAccountCredential.Initializer object?
   


The source code:


try

{

AdWordsAuthenticationConfig auth = Service.Auth;

 

X509Certificate2 certificate = new X509Certificate2(auth.CertificatePath, 
"notasecret", X509KeyStorageFlags.Exportable);

 

ServiceAccountCredential cred = new ServiceAccountCredential(

new ServiceAccountCredential.Initializer(auth.ServiceAccountEmail)

{

Scopes = new string[] { SheetsService.Scope.SpreadsheetsReadonly },

User = "[email protected]",

}.FromCertificate(certificate)

);

 

SheetsService service = new SheetsService(new BaseClientService.Initializer

{

HttpClientInitializer = cred

});

 

SpreadsheetsResource.ValuesResource.GetRequest request = 
service.Spreadsheets.Values.Get(spreadsheetId, range);

 

ValueRange response = request.Execute();

 

return response.Values;

}

catch (Exception ex)

{

...

}


Kind regards,

Charles. 


-- 
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