示例#1
0
        /// <summary>
        /// Creating this class will automatically try to log in and create a session.
        /// That way for each service we create we don't need to worry about the implementation of authentication and session.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="source"></param>
        protected GoogleService(string service, string username, string password, string source)
        {
            // Get the Auth token.
            string auth = ClientLogin.GetAuthToken(service, username, password, source);

            // Create a new session using this token.
            this.session = new GoogleSession(auth);
        }
示例#2
0
        public StringBuilder GetHTML(string feedUrl, string username, string password)
        {
            // Authenticate.
            string auth = ClientLogin.GetAuthToken("reader", username, password, "Sandworks.Google.App");

            // Query.
            using (GoogleSession session = new GoogleSession(auth))
            {
                DateTime d = new DateTime(2011, 12, 25);

                var feed = session.GetFeed("http://www.google.com/reader/atom/user/-/state/com.google/starred",
                    new GoogleParameter("n", "200"), new GoogleParameter("ot", session.GetUnixTimeNow().ToString()));

                foreach (var item in feed.Items)
                {
                    //Console.WriteLine("Author: " + item.Authors[0].Name);
                    //Console.WriteLine("Link: " + item.Links[0].Uri);
                    //Console.WriteLine("Title: " + item.Title.Text);
                    //Console.WriteLine();
                }
            }

            return new StringBuilder("suman");
        }
示例#3
0
文件: Editor.cs 项目: sted1234/Code
        private void button1_Click(object sender, EventArgs e)
        {
            // Authenticate.
            string auth = ClientLogin.GetAuthToken("reader", tbUserName.Text, tbPassword.Text, "Sandworks.Google.App");

            // Query.
            using (GoogleSession session = new GoogleSession(auth))
            {

                long unixTime = session.GetUnixTimeNow();
                TimeSpan startTimeDiffenceFromNow = DateTime.UtcNow - dtStarredAfter.Value.ToUniversalTime();
                long starredItemsSinceTime = unixTime - (long)startTimeDiffenceFromNow.TotalSeconds;

                var feed = session.GetFeed(tbFeedUrl.Text,
                    new GoogleParameter("n", tbLinkCount.Text)
                    ,new GoogleParameter("ot", starredItemsSinceTime.ToString())
                        );

                knownCategories = tbKnownCategories.Text.Split(',');
                for (int i = 0; i < knownCategories.Length; i++)
                    knownCategories[i] = knownCategories[i].Trim();

                foreach (var item in feed.Items)
                {
                    string matchedCategory = string.Empty;
                    foreach (SyndicationCategory category in item.Categories)
                    {
                        matchedCategory = knownCategories.FirstOrDefault(cat => cat.Equals(category.Label, StringComparison.InvariantCultureIgnoreCase));
                        if (!string.IsNullOrEmpty(matchedCategory))
                            break;
                    }
                    bool isCategorized = !string.IsNullOrEmpty(matchedCategory);
                    Links.Add(new Link { Title = item.Title.Text, AuthorName = item.Authors[0].Name, HyperLink = item.Links[0].Uri.ToString(), Category = matchedCategory?? string.Empty, IsCategorized = isCategorized });
                }
            }
            BuildContent();
            DialogResult = DialogResult.OK;
            Dispose();
        }