static void Main(string[] args) { string ME_ID = "116710411414066669240"; string SCOBLE_ID = "111091089527727420853"; GooglePlusService gpsvc = new GooglePlusService(); Person me = gpsvc.GetPerson(ME_ID); Console.WriteLine(string.Format("Name: {0} {1}", me.FirstName, me.LastName)); Console.WriteLine(string.Format("Profile: {0}", me.ProfileUrl)); // Post by me List<Post> posts = gpsvc.GetPosts(ME_ID); foreach (Post post in posts) { Console.WriteLine(post.Subject + " by " + post.Author + " (" + post.Source + ")."); } // Users following me List<string> followers = gpsvc.GetFollowerIDs(ME_ID); Console.WriteLine(me.FirstName + " is followed by " + followers.Count + " other google+ users."); foreach (string id in followers) { Person p = gpsvc.GetPerson(id); Console.Write(string.Format(" {0} {1} ", p.FirstName, p.LastName)); } // Users I follow List<string> followed = gpsvc.GetFollowedIDs(ME_ID); Console.WriteLine(me.FirstName + " follows " + followed.Count + " other google+ users."); foreach (string id in followed) { Person p = gpsvc.GetPerson(id); Console.WriteLine(string.Format(" {0} {1}, ", p.FirstName, p.LastName)); } Console.WriteLine("Hit any key to finish!"); Console.ReadKey(); }
/// <summary> /// Crawls a person starting from the start id /// </summary> /// <param name="start_id"></param> /// <param name="counter"></param> public void CrawlPerson(string start_id, int numberOfPersons, bool checkConnections) { string current_id; GooglePlusService gpsvc = new GooglePlusService(); InitializeVisitLists(); Console.WriteLine("Lists are initialized visited:{0}, visiting:{1}.", visitedIDList.Count, visitingIDList.Count); if (visitingIDList.Count == 0) { // seed the queue with first id visitingIDList.Enqueue(start_id); } while (numberOfPersons > 0) { if (visitingIDList.Count == 0) { break; } current_id = visitingIDList.Dequeue(); // did we see this user already if (visitedIDList.Contains(current_id)) { continue; } if (PersonInDb(current_id)) { if (!visitedIDList.Contains(current_id)) { visitedIDList.Add(current_id); } continue; } else { Stopwatch sp = new Stopwatch(); sp.Start(); Person p = gpsvc.GetPerson(current_id); List<Connection> followed = gpsvc.GetFollowedConnections(current_id); List<Connection> followers = gpsvc.GetFollowerConnections(current_id); if (checkConnections) { p.FollowersCount = followers.Count; p.FollowedByCount = followed.Count; } db.Persons.Add(p); db.SaveChanges(); if (!visitedIDList.Contains(current_id)) { visitedIDList.Add(current_id); } if (!checkConnections) { sp.Stop(); Console.WriteLine("{0}. {1} added. Followed By {2} users. Following {3} users. {4} ms", numberOfPersons, p.FirstName + " " + p.LastName, followers.Count, followed.Count, sp.ElapsedMilliseconds); numberOfPersons--; continue; } ProcessConnections(followed); ProcessConnections(followers); sp.Stop(); Console.WriteLine("{0}. {1} added. Followed By {2} users. Following {3} users. {4} ms", numberOfPersons, p.FirstName + " " + p.LastName, followers.Count, followed.Count, sp.ElapsedMilliseconds); numberOfPersons--; } } }