using Gmail API using Service Account
See original GitHub issueI am trying to use the gmail apis for sending mail from a .net windows application. Can we use a service account instead of the user credential to call the apis? and does this require to use the googleauthorisationbroker to authorise? Delegating domain-wide authority to the service account – is this a mandatory step to be done while we use the service account? I have created a project and downloaded the key and copied to my applciation folder. The following code is written
//created google account credential from service account key and included the scopes
using (var stream = new FileStream("_**key.json**_", FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);}
//call the google api using the credential.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
//send mail using the api
service.Users.Messages.Send(message, mailaddress).Execute();
}
But i get the follwing error
Error = {Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
Message[Bad Request] Location[ - ] Reason[failedPrecondition] Domain[global]
]
I have also tried using user credntials codes also, it works but does nt work in some systems. No error as such is shown but the Authorisation page is not shown. Any thoughts on these issues?
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (1 by maintainers)
Top Results From Across the Web
Can we access GMAIL API using Service Account?
For C# Gmail API v1, you can use the following code to get the gmail service. Use gmail service to read emails. Once...
Read more >Access GSuite APIs on your domain using a service account
From the project, click on ENABLE APIS AND SERVICES and search for the Gmail API. Click on ENABLE. You now have the Gmail...
Read more >Implement server-side authorization | Gmail
To get started using Gmail API, you need to first use the setup tool, which guides you through creating a project in the...
Read more >How to a create a Gmail service account
A service account provides an efficient way to connect multiple mailboxes to Ebsta. Mailbox management is undertaken by an Administrator, bypassing the need ......
Read more >Configure Google Workspace service account
Gmail / Google Workspace (G Suite) Service Accounts are used for various mail access management tasks, for example to mass-authorize RG Email Sidebar...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Service accounts will only work with Gsuite email accounts. The admin of the Gsuite (domain) account will have to grant the service account access to the users email account. Unfortunately i don’t have access to a Gsuite account so cant help you set it up. This might help Perform G Suite Domain-Wide Delegation of Authority
If this is a normal Gmail user account you are trying to access then you cant use a service account. You will either have to go though the SMTP / IMAP servers or using Oauth2 to authenticate the user.
this is related to #987. now admin privileges are needed to open the listening socket at least in Windows 7 and 8.1.