如何通过在C#中提供用户名和密码来获取用户的taskList

时间:2014-04-27 04:57:13

标签: email c#-4.0 task

我正在开发控制台应用程序,用于通过提供用户名和密码来提取用户的任务和任务列表。我用谷歌搜索了几次,但没有找到任何简单的工作代码,  我的代码在这里:

       UserCredential credential;
       using (var stream = new FileStream("client_secrets.json", FileMode.Open,   FileAccess.Read))
        {
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { TasksService.Scope.Tasks },
                "shyam.sundar@gmai.com", CancellationToken.None, new FileDataStore("Tasks.Auth.Store")).Result;
        }            
       //credential=new UserCredential(
        // Create the service.
        var service = new TasksService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Tasks API Sample",
        }); 
     ListTaskLists(service); //retun task list of user whose email is used to get secret key and id. It does not return task list of shyam.sudnar@gmail.com

由于 Shyams

1 个答案:

答案 0 :(得分:0)

使用有效的电子邮件地址。它会起作用

    UserCredential credential;
   using (var stream = new FileStream("client_secrets.json", FileMode.Open,   FileAccess.Read))
    {
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            new[] { TasksService.Scope.Tasks },
            "shyam.sundar@gmail.com", CancellationToken.None, new FileDataStore("Tasks.Auth.Store")).Result;
    }            
   //credential=new UserCredential(
    // Create the service.
    var service = new TasksService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "Tasks API Sample",
    }); 
 ListTaskLists(service)