Click here to Skip to main content
14,242,862 members
Rate this:
Please Sign up or sign in to vote.
See more:
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"]);  //5;
                messages = request.Execute().Messages;
				List<string> lstRemove = new List<string>() { "UNREAD" };
				
				/// Read the individual message and output as List<Email>
                for (int index = 0; index < messages.Count; index++)
                {
				//... Do the code...
				}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100