Ejemplo n.º 1
0
        /// <summary>
        /// Get User Info
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public ProfileInfo GetUserInfo(string code, string state)
        {
            var userProfilinfo = new ProfileInfo();
            var Accesstoan     = linkedIn.GetAccessToken(code, WebConfigurationManagement.LinkedinRedirect_uri);

            if (Accesstoan.Status == LinkedInResponseStatus.OK)
            {
                LinkedInGetMemberOptions lnoption = new LinkedInGetMemberOptions();
                lnoption.BasicProfileOptions.SelectAll();
                lnoption.EmailProfileOptions.SelectAll();
                lnoption.FullProfileOptions.SelectAll();
                var Userinfo = linkedIn.GetMember(lnoption);
                if (Userinfo.Status == LinkedInResponseStatus.OK)
                {
                    userProfilinfo.FirstName = linkedIn.CurrentUser.FirstName;
                    userProfilinfo.LastName  = linkedIn.CurrentUser.LastName;
                    //  userProfilinfo.Phone = Userinfo.Result.BasicProfile.PhoneticFirstName;
                    userProfilinfo.ProfilePicture = ((LinkedIn.NET.Members.LinkedInPerson)(Userinfo.Result.BasicProfile)).PictureUrl;
                    userProfilinfo.ProfileURL     = Userinfo.Result.BasicProfile.PublicProfileUrl;
                    userProfilinfo.Email          = Userinfo.Result.EmailProfile.EmailAddress;
                    userProfilinfo.IsSuccess      = true;
                }
                else
                {
                    userProfilinfo.IsSuccess    = false;
                    userProfilinfo.ErrorMessage = Userinfo.Message;
                }
            }
            else
            {
                userProfilinfo.IsSuccess    = false;
                userProfilinfo.ErrorMessage = Accesstoan.Message;
            }
            return(userProfilinfo);
        }
Ejemplo n.º 2
0
        // The code in this method is heavily borrowed from the LinkedIn.NET's LNTest "authenticate" method (DlgExample.cs)
        protected void Authenticate()
        {
            if (linkedInClient != null)
            {
                var options = new LinkedInAuthorizationOptions
                {
                    RedirectUrl = REDIRECT_URL,
                    Permissions = LinkedInPermissions.Connections | LinkedInPermissions.ContactsInfo |
                                  LinkedInPermissions.EmailAddress | LinkedInPermissions.FullProfile |
                                  LinkedInPermissions.GroupDiscussions | LinkedInPermissions.Messages |
                                  LinkedInPermissions.Updates,
                    State = STATE
                };

                //create new instance of authorization dialog using authorization link built by _Client
                var dlgAuth = new DlgAuthorization(linkedInClient.GetAuthorizationUrl(options));

                if (dlgAuth.ShowDialog(this) == DialogResult.OK)
                {
                    //get access token using authorization code received
                    var response = linkedInClient.GetAccessToken(dlgAuth.AuthorizationCode, REDIRECT_URL);

                    if (response.Result != null && response.Status == LinkedInResponseStatus.OK)
                    {
                        accessToken = response.Result.AccessToken;
                        SaveConfiguration();
                    }
                }
                else
                {
                    //show error information
                    MessageBox.Show(dlgAuth.OauthErrorDescription, dlgAuth.OauthError);
                }
            }
        }