I am trying to do a very simple task. Getting a list of Emails using the api of Google.Apis. This is the error that I am getting:
Google.Apis.Requests.RequestError
Delegation denied for association8385@gmail.com [403]
Errors [
Message[Delegation denied for association8385@gmail.com] Location[ - ] Reason[forbidden]
Domain[global] ]
Here is my code:
using (FileStream stream = new(emailSettings.Value.ClientCredentials, FileMode.Open,
FileAccess.Read))
{
string folderPath = emailSettings.Value.CredentialsInfo;
string filePath = Path.Combine(folderPath, "APITokenCredentials");
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets,
_scopes,
"user",
CancellationToken.None,
new FileDataStore(filePath, true)).Result;
}
_service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credential,
ApplicationName = emailSettings.Value.ApplicationName
});
UsersResource.MessagesResource.ListRequest listRequest =
_service.Users.Messages.List(_hostAddress);
listRequest.LabelIds = "INBOX";
listRequest.IncludeSpamTrash = false;
listRequest.Q = "is:unread";
ListMessagesResponse listReqponse = listRequest.Execute() ;
The crash occurs when I try to execute listRequest.Execute()
I have enabled the Gmail API and People Api.I have created the ClientCredentials json. Also I have created my OAuth 2.0 Client IDs as a Web Application. When the service is created the necessary token is created. For this simple task I suspect that it is a configuration issue.
Can somebody point me in the right direction