Hi,
I can read/modify gmails from my own Gmail account via Gmail API using its credentials
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
But now, IT operation provide me a
shared Gmail or delegate. So I want to access, read/modify from that delegate email.
How can I access using Gmail API?
Is there any example?
Most of the code in Gmail API sites are in Python and Java which I don't understand.
please shed some lights..
What I have tried:
I can access, read my own mail by using Gmail API -
private static string[] Scopes = { GmailService.Scope.GmailModify };
private UserCredential _credential;
private string credPath = "token.json";
public UserCredential GetCredential()
{
using (var stream =
new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
return _credential;
}
----------------------------------------------------------------------
GmailCredentials Info = new GmailCredentials();
private static string ApplicationName = "xxxxx";
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = GetCredential(),
ApplicationName = ApplicationName,
});
UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me");
request.Q = ConfigurationManager.AppSettings["filter"];
request.MaxResults = Convert.ToInt64(ConfigurationManager.AppSettings["maxCount"]);
messages = request.Execute().Messages;
List<string> lstRemove = new List<string>() { "UNREAD" };
for (int index = 0; index < messages.Count; index++)
{
}