Exemple #1
0
        public string GetUsername()
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("https://api.linkedin.com/v1/people/~"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, Token, TokenSecret);

            return(result.Element("person").Element("first-name").Value + " " + result.Element("person").Element("last-name").Value);
        }
        /// <summary>
        /// See: http://developer.linkedin.com/docs/DOC-1004
        /// </summary>
        /// <returns></returns>
        public IEnumerable <ChannelContact> GetContacts()
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("http://api.linkedin.com/v1/people/~/connections"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            if (result.Element("connections").Elements().Count() == 0)
            {
                yield break;
            }

            foreach (var response in result.Elements("connections").Elements("person"))
            {
                ChannelContact contact = new ChannelContact();
                contact.Profile.ChannelProfileKey = response.Element("id").Value;
                contact.Person.Firstname          = response.Element("first-name").Value;
                contact.Person.Lastname           = response.Element("last-name").Value;

                contact.Profile.Title = response.Element("headline").Value;
                contact.Profile.Url   = response.Element("site-standard-profile-request").Element("url").Value;

                if (response.Element("picture-url") != null)
                {
                    contact.Profile.ChannelAvatar     = new ChannelAvatar();
                    contact.Profile.ChannelAvatar.Url = response.Element("picture-url").Value;
                }

                contact.Profile.SourceAddress = new SourceAddress(response.Element("id").Value, contact.Person.Name);
                contact.Profile.ProfileType   = ProfileType.Social;

                yield return(contact);
            }
        }
Exemple #3
0
        public bool ValidateReturnValue(string verifier)
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("https://api.linkedin.com/uas/oauth/accessToken"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, Token, TokenSecret, verifier);

            var parts = NameValueParser.GetCollection(result, "&");

            if (ChannelContext.Current == null)
            {
                throw new ArgumentNullException("ChannelContext.Current");
            }

            // Remove token from session
            SafeSession.Current.Remove("/Channels/LinkedIn/Redirect/Token");
            SafeSession.Current.Remove("/Channels/LinkedIn/Redirect/TokenSecret");

            // 7. Save auth keys
            ChannelContext.Current.ClientContext.SaveSetting("/Channels/LinkedIn/AuthToken", parts["oauth_token"]);
            ChannelContext.Current.ClientContext.SaveSetting("/Channels/LinkedIn/AuthSecret", parts["oauth_token_secret"]);

            Token       = parts["oauth_token"];
            TokenSecret = parts["oauth_token_secret"];

            return(true);
        }
        public void UpdateMyStatus(ChannelStatusUpdate update)
        {
            var element = new XElement("current-status", update.Status.StripHtml());

            LinkedInWebRequest.Put(new Uri("http://api.linkedin.com/v1/people/~/current-status"), element.ToString(),
                                   ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);
        }
        public ChannelSocialProfile GetProfile()
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url)"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            var response = result.Element("person");

            return(new ChannelSocialProfile
            {
                Id = response.Element("id").Value,
                FullName = String.Concat(response.Element("first-name").Value, " ", response.Element("last-name").Value),
                AvatarUrl = response.Element("picture-url") == null ? String.Empty : response.Element("picture-url").Value
            });
        }
Exemple #6
0
        public Uri BuildRedirectUri()
        {
            // 1. Get Auth Token
            var result = LinkedInWebRequest.PerformRequest(new Uri("https://api.linkedin.com/uas/oauth/requestToken"),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret);
            var parts = NameValueParser.GetCollection(result, "&");

            this.Token       = parts["oauth_token"];
            this.TokenSecret = parts["oauth_token_secret"];

            // Save data in session for re-materialization
            SafeSession.Current["/Channels/LinkedIn/Redirect/Token"]       = Token;
            SafeSession.Current["/Channels/LinkedIn/Redirect/TokenSecret"] = TokenSecret;

            return(new Uri("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + Token + "&oauth_callback=" + BuildEnvironmentUrl()));
        }
        public IEnumerable <ChannelStatusUpdate> GetUserUpdates(string username, int pageSize)
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri(String.Concat("http://api.linkedin.com/v1/people/id=", username, ":(current-status,current-status-timestamp)")),
                                                           ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            if (result.Elements("person").Elements().Count() == 0)
            {
                yield break;
            }

            foreach (var response in result.Elements("person"))
            {
                var update = new ChannelStatusUpdate();

                update.Status = response.Element("current-status").Value;

                var ts = TimeSpan.FromMilliseconds(Double.Parse(response.Element("current-status-timestamp").Value));
                update.DatePosted = ((long)ts.TotalSeconds).ToUnixTime();

                yield return(update);
            }
        }
        public IEnumerable <ChannelStatusUpdate> GetUpdates(int pageSize)
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("http://api.linkedin.com/v1/people/~/network"), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            if (result.Element("network").Elements().Count() == 0)
            {
                yield break;
            }

            foreach (var response in result.Element("network").Element("updates").Elements("update"))
            {
                ChannelStatusUpdate statusUpdate = null;
                var updateType = (LinkedInUpdateType)Enum.Parse(typeof(LinkedInUpdateType),
                                                                response.Element("update-type").Value);

                switch (updateType)
                {
                case LinkedInUpdateType.ANSW:
                    // TODO : Answer Update
                    break;

                case LinkedInUpdateType.APPS:
                case LinkedInUpdateType.APPM:
                    // TODO : Application Update
                    break;

                case LinkedInUpdateType.CONN:
                case LinkedInUpdateType.NCON:
                case LinkedInUpdateType.CCEM:
                    // Connection updates
                    statusUpdate = new ChannelStatusUpdate
                    {
                        ChannelStatusKey = BuildChannelStatusKey(response),
                        From             = BuildSourceAddress(response),
                        Status           = BuildConnectionStatusMessage(response),
                        DatePosted       = GetDateTime(response)
                    };
                    break;

                case LinkedInUpdateType.JOBS:
                case LinkedInUpdateType.JOBP:
                    // TODO : Posted a job
                    break;

                case LinkedInUpdateType.JGRP:
                    // TODO : Joined a group
                    break;

                case LinkedInUpdateType.PICT:
                case LinkedInUpdateType.PICU:
                    // TODO : Changed a picture
                    break;

                case LinkedInUpdateType.RECU:
                case LinkedInUpdateType.PREC:
                    // TODO : Recommendations
                    break;

                case LinkedInUpdateType.PRFU:
                case LinkedInUpdateType.PROF:
                    // TODO : Changed profile
                    break;

                case LinkedInUpdateType.QSTN:
                    // TODO : Question update
                    break;

                case LinkedInUpdateType.STAT:
                    // Status update
                    statusUpdate = new ChannelStatusUpdate
                    {
                        ChannelStatusKey = BuildChannelStatusKey(response),
                        From             = BuildSourceAddress(response),
                        Status           = response.Element("update-content").Element("person").Element("current-status").Value,
                        DatePosted       = GetDateTime(response)
                    };
                    break;
                }

                if (statusUpdate != null)
                {
                    yield return(statusUpdate);
                }
            }
        }