Пример #1
0
        public ActionResult Index()
        {
            var accessToken = (AccessToken)Session["accessToken"];

            if (accessToken != null)
            {
                // create the client
                var client = new LinkedINRestClient(consumerKey, consumerSecret, accessToken);
                // retrieve the profile
                try
                {
                    var id_field          = new[] { new ProfileField("id") };
                    var tiny_user_profile = client.RetrieveCurrentMemberProfile(id_field);
                    var USERID            = tiny_user_profile.Id;

                    var all = "id,first-name,last-name,maiden-name,formatted-name,phonetic-first-name,phonetic-last-name,";
                    all += "formatted-phonetic-name,headline,location:(name,country:(code)),industry,distance,relation-to-viewer:(distance),";
                    all += "last-modified-timestamp,current-share,network,connections,num-connections,num-connections-capped,summary,";
                    all += "specialties,proposal-comments,associations,honors,interests,positions,publications,patents,languages,skills,";
                    all += "certifications,educations,courses,volunteer,three-current-positions,three-past-positions,num-recommenders,";
                    all += "recommendations-received,phone-numbers,im-accounts,twitter-accounts,primary-twitter-account,bound-account-types,";
                    all += "mfeed-rss-url,following,job-bookmarks,group-memberships,suggestions,date-of-birth,main-address,member-url-resources,";
                    all += "picture-url,public-profile-url,related-profile-views";
                    var fields = new[] { new ProfileField(all) };

                    //  USERID = "GP6NLJzhwV";  maysam
                    //  USERID = "DDlt4Qzq2Q";  martin

                    var     user_profile = client.RetrieveProfileById(USERID, fields);
                    Profile profile      = new Profile(user_profile);

                    List <GroupMembership> group_memberships;
                    try
                    {
                        group_memberships = client.RetrieveGroups(USERID);
                    }
                    catch (Exception e)
                    {
                        group_memberships = new List <GroupMembership>(user_profile.GroupMemberships);
                    }
                    foreach (GroupMembership group in group_memberships)
                    {
                        try
                        {
                            var group_posts = client.RetrieveGroupPostsByID(USERID, group.Key);
                            foreach (var post in group_posts)
                            {
                                profile.add(
                                    new GroupPost(
                                        post.title,
                                        post.likes.Total,
                                        post.Comments.Count,
                                        post.SiteGroupPostUrl,
                                        post.CreationTimestamp
                                        )
                                    );
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("ERROR:");
                            System.Diagnostics.Debug.WriteLine(e);
                        }
                        try
                        {
                            var group_posts = client.RetrieveGroupPostCommentsByID(USERID, group.Key);
                            foreach (var post in group_posts)
                            {
                                foreach (var comment in post.Comments)
                                {
                                    if (comment.Creator.Id == USERID)
                                    {
                                        profile.add(
                                            new GroupPostComment(
                                                post.title,
                                                comment.Text,
                                                post.SiteGroupPostUrl,
                                                comment.CreationTimestamp
                                                )
                                            );
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("ERROR:");
                            System.Diagnostics.Debug.WriteLine(e);
                        }
                    }
                    //  "VIRL" is something that I liked, clearly out of our scope here
                    var types = new[] { "SHAR", "PRFX" };
                    foreach (var type in types)
                    {
                        var recent_updates = client.RetrieveUpdatesById(USERID, type);
                        foreach (var update in recent_updates)
                        {
                            try
                            {
                                String content = type + " !!! " + update.ToString();
                                if (update.UpdateContent.Person.CurrentShare == null)
                                {
                                    content = type + " ??? " + update.ToString();
                                }
                                else
                                {
                                    content = update.UpdateContent.Person.CurrentShare.Comment;
                                    if (content == "" || content == null)
                                    {
                                        content = update.UpdateContent.Person.CurrentShare.Content.title; // || update.UpdateContent.Person.CurrentShare.Comment;
                                    }
                                }
                                var likes_count = update.NumLikes;
                                if (update.Likes != null)
                                {
                                    likes_count = update.Likes.Total;
                                }
                                var comments_count = 0;
                                if (update.UpdateComments != null)
                                {
                                    comments_count = update.UpdateComments.Total;
                                }

                                profile.add(
                                    new UserPost(
                                        content,
                                        likes_count,
                                        comments_count,
                                        update.UpdateUrl,
                                        update.TimeStamp
                                        )
                                    );
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine("ERROR: on line " + e.Source);
                                System.Diagnostics.Debug.WriteLine(e);
                            }
                        }
                    }
                    profile.processPercentages();
                    return(View("Profile", profile));
                }
                catch (LinkedINUnauthorizedException)
                {
                    // clear the access token
                    Session.Remove("accessToken");

                    // return the unauthorized view
                    return(View("Login"));
                }
                catch (Exception e)
                {
                    return(View("Error", e));
                }
            }

            // return the unauthorized view
            return(View("Login"));
        }
Пример #2
0
        public ActionResult Index()
        {
            var accessToken = (AccessToken) Session["accessToken"];
            if (accessToken != null)
            {
                // create the client
                var client = new LinkedINRestClient(consumerKey, consumerSecret, accessToken);
                // retrieve the profile
                try
                {
                    var id_field = new[] { new ProfileField("id") };
                    var tiny_user_profile = client.RetrieveCurrentMemberProfile(id_field);
                    var USERID = tiny_user_profile.Id;

                    var all = "id,first-name,last-name,maiden-name,formatted-name,phonetic-first-name,phonetic-last-name,";
                    all += "formatted-phonetic-name,headline,location:(name,country:(code)),industry,distance,relation-to-viewer:(distance),";
                    all += "last-modified-timestamp,current-share,network,connections,num-connections,num-connections-capped,summary,";
                    all += "specialties,proposal-comments,associations,honors,interests,positions,publications,patents,languages,skills,";
                    all += "certifications,educations,courses,volunteer,three-current-positions,three-past-positions,num-recommenders,";
                    all += "recommendations-received,phone-numbers,im-accounts,twitter-accounts,primary-twitter-account,bound-account-types,";
                    all += "mfeed-rss-url,following,job-bookmarks,group-memberships,suggestions,date-of-birth,main-address,member-url-resources,";
                    all += "picture-url,public-profile-url,related-profile-views";
                    var fields = new[] { new ProfileField(all) };

                    //  USERID = "GP6NLJzhwV";  maysam
                    //  USERID = "DDlt4Qzq2Q";  martin

                    var user_profile = client.RetrieveProfileById(USERID, fields);
                    Profile profile = new Profile(user_profile);

                    List<GroupMembership> group_memberships;
                    try
                    {
                        group_memberships = client.RetrieveGroups(USERID);
                    }
                    catch (Exception e)
                    {
                        group_memberships = new List<GroupMembership>(user_profile.GroupMemberships);
                    }
                    foreach (GroupMembership group in group_memberships)
                    {
                        try
                        {
                            var group_posts = client.RetrieveGroupPostsByID(USERID, group.Key);
                            foreach (var post in group_posts)
                            {
                                profile.add(
                                    new GroupPost(
                                        post.title,
                                        post.likes.Total,
                                        post.Comments.Count,
                                        post.SiteGroupPostUrl,
                                        post.CreationTimestamp
                                        )
                                    );
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("ERROR:");
                            System.Diagnostics.Debug.WriteLine(e);
                        }
                        try
                        {
                            var group_posts = client.RetrieveGroupPostCommentsByID(USERID, group.Key);
                            foreach (var post in group_posts)
                            {
                                foreach (var comment in post.Comments)
                                {
                                    if (comment.Creator.Id == USERID)
                                    {
                                        profile.add(
                                            new GroupPostComment(
                                                post.title,
                                                comment.Text,
                                                post.SiteGroupPostUrl,
                                                comment.CreationTimestamp
                                                )
                                            );
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("ERROR:");
                            System.Diagnostics.Debug.WriteLine(e);
                        }
                    }
                    //  "VIRL" is something that I liked, clearly out of our scope here
                    var types = new[] { "SHAR", "PRFX" };
                    foreach (var type in types)
                    {
                        var recent_updates = client.RetrieveUpdatesById(USERID, type);
                        foreach (var update in recent_updates)
                        {

                            try
                            {
                                String content = type + " !!! " + update.ToString();
                                if (update.UpdateContent.Person.CurrentShare == null)
                                {
                                    content = type + " ??? " + update.ToString();
                                }
                                else
                                {
                                    content = update.UpdateContent.Person.CurrentShare.Comment;
                                    if (content == "" || content == null)
                                        content = update.UpdateContent.Person.CurrentShare.Content.title; // || update.UpdateContent.Person.CurrentShare.Comment;
                                }
                                var likes_count = update.NumLikes;
                                if (update.Likes != null)
                                    likes_count = update.Likes.Total;
                                var comments_count = 0;
                                if (update.UpdateComments != null)
                                    comments_count = update.UpdateComments.Total;

                                profile.add(
                                    new UserPost(
                                        content,
                                        likes_count,
                                        comments_count,
                                        update.UpdateUrl,
                                        update.TimeStamp
                                        )
                                );
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine("ERROR: on line " + e.Source);
                                System.Diagnostics.Debug.WriteLine(e);
                            }
                        }
                    }
                    profile.processPercentages();
                    return View("Profile", profile);
                }
                catch (LinkedINUnauthorizedException)
                {
                    // clear the access token
                    Session.Remove("accessToken");

                    // return the unauthorized view
                    return View("Login");
                }
                catch (Exception e)
                {
                    return View("Error", e);
                }
            }

            // return the unauthorized view
            return View("Login");
        }