AccessTokenGet() 공개 메소드

Exchange the request token for an access token.
public AccessTokenGet ( string authToken ) : void
authToken string The oauth_token is supplied by Twitter's authorization page following the callback.
리턴 void
예제 #1
0
        public string LinkedInAuth()
        {
            string email = "";

            try
            {
                oAuthLinkedIn _oauth         = new oAuthLinkedIn();
                string        oauth_token    = Request.QueryString["oauth_token"];
                string        oauth_verifier = Request.QueryString["oauth_verifier"];

                if (oauth_token != null && oauth_verifier != null)
                {
                    Application["oauth_token"]    = oauth_token;
                    Application["oauth_verifier"] = oauth_verifier;
                    _oauth.Token       = oauth_token;
                    _oauth.TokenSecret = Application["reuqestTokenSecret"].ToString();
                    _oauth.Verifier    = oauth_verifier;
                    _oauth.AccessTokenGet(oauth_token);

                    string emailResponse = _oauth.APIWebRequest("GET", "https://api.linkedin.com/v1/people/~/email-address", null);
                    email = ParselinkedInXMl(emailResponse, "<email-address>", "</email-address>");
                    string nameResponse = _oauth.APIWebRequest("GET", "https://api.linkedin.com/v1/people/~", null);
                    FirstName        = ParselinkedInXMl(nameResponse, "<first-name>", "</first-name>");
                    LastName         = ParselinkedInXMl(nameResponse, "<last-name>", "</last-name>");
                    lblAlertMsg.Text = email + " sucessfully Login with LinkedIn" + FirstName + "  " + LastName;
                    Session.Remove(SessionKeys.ServiceProvider);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
            return(email);
        }
예제 #2
0
    protected void btnGetAccessToken_Click(object sender, EventArgs e)
    {
        _oauth.Token       = txtoAuth_token.Text;
        _oauth.TokenSecret = txtTokenSecret.Text;
        _oauth.Verifier    = txtoAuth_verifier.Text;

        _oauth.AccessTokenGet(txtoAuth_token.Text);
        txtAccessToken.Text       = _oauth.Token;
        txtAccessTokenSecret.Text = _oauth.TokenSecret;
        btnGetAccessToken.Focus();
    }
예제 #3
0
        private void btnGetAcToken_Click(object sender, EventArgs e)
        {
            _oauth.Token       = txtOauth_token.Text;
            _oauth.TokenSecret = txtRequestTokenSecret.Text;
            _oauth.Verifier    = txtOauth_verify.Text;

            _oauth.AccessTokenGet(txtOauth_token.Text);

            txtOauth_Access_token.Text       = _oauth.Token;
            txtOauth_Access_tokenSecret.Text = _oauth.TokenSecret;
            btnUpdateStatus.Enabled          = true;
            btnGetProfileDetail.Enabled      = true;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        gettoken        = Session["Session_OToken"].ToString();
        getotokensecret = Session["Session_OTokenSecret"].ToString();
        getverifier     = Request.QueryString["oauth_verifier"];

        //Get Access Token
        _oauth.Token       = gettoken;
        _oauth.TokenSecret = getotokensecret;
        _oauth.Verifier    = getverifier;

        _oauth.AccessTokenGet(gettoken);
        accessToken       = _oauth.Token;
        accessTokenSecret = _oauth.TokenSecret;

        _oauth.Token       = accessToken;
        _oauth.TokenSecret = accessTokenSecret;
        _oauth.Verifier    = getverifier;


        //Display profile
        string response = _oauth.APIWebRequest("GET", "https://api.linkedin.com/v1/people/~/", null);

        //txtApiResponse.Text = response;

        XmlDocument xml = new XmlDocument();

        xml.LoadXml(response); // suppose that myXmlString contains "<Names>...</Names>"

        XmlNodeList xnList = xml.SelectNodes("/person");

        foreach (XmlNode xn in xnList)
        {
            string firstName   = xn["first-name"].InnerText;
            string lastName    = xn["last-name"].InnerText;
            string CompanyName = xn["headline"].InnerText;

            txtFirstName.Text = firstName;
            txtLastName.Text  = lastName;
            //lblCompanyName.Text = CompanyName;
        }
        XmlNodeList xnList1   = xml.SelectNodes("/");
        string      response2 = _oauth.APIWebRequest("GET", "https://api.linkedin.com/v1/people/~/email-address", null);

        xml.LoadXml(response2);
        foreach (XmlNode Xnn in xnList1)
        {
            string emailAddress = Xnn["email-address"].InnerText;
            txtEmailID.Text = emailAddress;
        }
    }
        public void GetAccessToken()
        {
            LinkedInProfile objProfile = new LinkedInProfile();

            LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
            LinkedInHelper liHelper       = new LinkedInHelper();
            User           user           = (User)Session["LoggedUser"];
            string         oauth_token    = Request.QueryString["oauth_token"];
            string         oauth_verifier = Request.QueryString["oauth_verifier"];

            try
            {
                if (oauth_token != null && oauth_verifier != null)
                {
                    try
                    {
                        _oauth.Token = oauth_token;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.TokenSecret = Session["reuqestTokenSecret"].ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.Verifier = oauth_verifier;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        _oauth.AccessTokenGet(oauth_token);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }

                    // Update Access Token in DB
                    try
                    {
                        int res = UpdateLDToken(user.Id.ToString(), _oauth.Token);
                    }
                    catch { };
                    //***********************

                    Session.Remove("oauth_token");
                    Session.Remove("oauth_TokenSecret");

                    try
                    {
                        objUserProfile = objProfile.GetUserProfile(_oauth);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        liHelper.GetLinkedInUserProfile(objUserProfile, _oauth, user);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        // liHelper.getLinkedInNetworkUpdate(_oauth,user);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    Session["LinkedInUser"] = _oauth;
                    Session["datatable"]    = null;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
        }
예제 #6
0
        public string GetLinkedinCompanyPage(string oauth_token, string oauth_verifier, string reuqestTokenSecret, string consumerKey, string consumerSecret, string UserId, string GroupId)
        {
            List <Helper.AddlinkedinCompanyPage> lstAddLinkedinPage = new List <Helper.AddlinkedinCompanyPage>();
            string        ret    = string.Empty;
            oAuthLinkedIn _oauth = new oAuthLinkedIn();

            try
            {
                _oauth.ConsumerKey = consumerKey;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                _oauth.ConsumerSecret = consumerSecret;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                _oauth.Token = oauth_token;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                _oauth.TokenSecret = reuqestTokenSecret;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                _oauth.Verifier = oauth_verifier;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                _oauth.AccessTokenGet(oauth_token);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            XmlDocument xmlResult  = new XmlDocument();
            XmlDocument xmlCompany = new XmlDocument();

            GlobusLinkedinLib.LinkedIn.Core.PeopleMethods.People peopleConnection = new GlobusLinkedinLib.LinkedIn.Core.PeopleMethods.People();
            xmlResult = peopleConnection.Get_UserProfile(_oauth);
            string UserProfileId = xmlResult.GetElementsByTagName("id")[0].InnerText;
            string response      = _oauth.APIWebRequest("GET", GlobusLinkedinLib.App.Core.Global.GetCompanyUrl, null);

            string strLidPageDiv = string.Empty;

            xmlCompany.Load(new StringReader(response));

            string     cnt  = string.Empty;
            XmlElement root = xmlCompany.DocumentElement;

            if (root.HasAttribute("total"))
            {
                cnt = root.GetAttribute("total");
            }
            int total = Convert.ToInt16(cnt);

            if (total != 0)
            {
                for (int i = 0; i < total; i++)
                {
                    Helper.AddlinkedinCompanyPage objAddLinkedinPage = new Helper.AddlinkedinCompanyPage();
                    objAddLinkedinPage.PageId   = xmlCompany.GetElementsByTagName("id")[i].InnerText;
                    objAddLinkedinPage.PageName = xmlCompany.GetElementsByTagName("name")[i].InnerText;
                    objAddLinkedinPage._Oauth   = _oauth;

                    lstAddLinkedinPage.Add(objAddLinkedinPage);
                }
            }

            return(new JavaScriptSerializer().Serialize(lstAddLinkedinPage));
        }
예제 #7
0
        public string AddLinkedinAccount(string oauth_token, string oauth_verifier, string reuqestTokenSecret, string consumerKey, string consumerSecret, string UserId, string GroupId)
        {
            try
            {
                logger.Error("AddLinkedinAccount()");

                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

                string                      ret            = string.Empty;
                LinkedInProfile             objProfile     = new LinkedInProfile();
                LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile();
                objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                oAuthLinkedIn _oauth = new oAuthLinkedIn();
                objLinkedInAccount = new LinkedInAccount();
                #region Get linkedin Profile data from Api
                try
                {
                    _oauth.ConsumerKey = consumerKey;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.ConsumerSecret = consumerSecret;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.Token = oauth_token;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.TokenSecret = reuqestTokenSecret;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.Verifier = oauth_verifier;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    _oauth.AccessTokenGet(oauth_token);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                try
                {
                    objUserProfile = objProfile.GetUserProfile(_oauth);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                #endregion
                dynamic data = objUserProfile;
                try
                {
                    #region LinkedInAccount
                    objLinkedInAccount.UserId         = Guid.Parse(UserId);
                    objLinkedInAccount.LinkedinUserId = data.id.ToString();
                    try
                    {
                        objLinkedInAccount.EmailId = data.email.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    objLinkedInAccount.LinkedinUserName = data.first_name.ToString() + data.last_name.ToString();
                    objLinkedInAccount.OAuthToken       = _oauth.Token;
                    objLinkedInAccount.OAuthSecret      = _oauth.TokenSecret;
                    objLinkedInAccount.OAuthVerifier    = _oauth.Verifier;
                    try
                    {
                        objLinkedInAccount.ProfileImageUrl = data.picture_url.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        objLinkedInAccount.ProfileUrl = data.profile_url.ToString();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    #endregion
                    #region SocialProfiles
                    try
                    {
                        objLinkedInAccount.Connections = data.connections;
                        objLinkedInAccount.IsActive    = true;
                        objSocialProfile.UserId        = Guid.Parse(UserId);
                        objSocialProfile.ProfileType   = "linkedin";
                        objSocialProfile.ProfileId     = data.id.ToString();
                        objSocialProfile.ProfileStatus = 1;
                        objSocialProfile.ProfileDate   = DateTime.Now;
                        objSocialProfile.Id            = Guid.NewGuid();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                    }
                    #endregion SocialProfiles
                    #region Add TeamMemberProfile
                    try
                    {
                        Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                        objTeamMemberProfile                  = new Domain.Myfashion.Domain.TeamMemberProfile();
                        objTeamMemberProfile.Id               = Guid.NewGuid();
                        objTeamMemberProfile.TeamId           = objTeam.Id;
                        objTeamMemberProfile.Status           = 1;
                        objTeamMemberProfile.ProfileType      = "linkedin";
                        objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                        objTeamMemberProfile.ProfileId        = objLinkedInAccount.LinkedinUserId;
                        objTeamMemberProfile.ProfileName      = objLinkedInAccount.LinkedinUserName;
                        objTeamMemberProfile.ProfilePicUrl    = objLinkedInAccount.ProfileImageUrl;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                try
                {
                    if (!objLinkedInAccountRepository.checkLinkedinUserExists(objLinkedInAccount.LinkedinUserId, Guid.Parse(UserId)))
                    {
                        objLinkedInAccountRepository.addLinkedinUser(objLinkedInAccount);
                        ret = "LinkedIn Account Added Successfully";
                    }
                    else
                    {
                        ret = "LinkedIn Account Already Exist";
                    }
                    if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                    {
                        objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                    }
                    if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objLinkedInAccount.LinkedinUserId))
                    {
                        objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                    }

                    #region Add LinkedIn Feeds
                    LinkedInNetwork objln = new LinkedInNetwork();
                    List <LinkedInNetwork.Network_Updates> userUPdate = objln.GetNetworkUpdates(_oauth, 20);
                    foreach (var item in userUPdate)
                    {
                        try
                        {
                            objLinkedInFeed            = new Domain.Myfashion.Domain.LinkedInFeed();
                            objLinkedInFeed.Feeds      = item.Message;
                            objLinkedInFeed.FromId     = item.PersonId;
                            objLinkedInFeed.FromName   = item.PersonFirstName + " " + item.PersonLastName;
                            objLinkedInFeed.FeedsDate  = Convert.ToDateTime(item.DateTime);
                            objLinkedInFeed.EntryDate  = DateTime.Now;
                            objLinkedInFeed.ProfileId  = objLinkedInAccount.LinkedinUserId;
                            objLinkedInFeed.Type       = item.UpdateType;
                            objLinkedInFeed.UserId     = Guid.Parse(UserId);
                            objLinkedInFeed.FromPicUrl = item.PictureUrl;
                            objLinkedInFeed.ImageUrl   = item.ImageUrl;
                            objLinkedInFeed.FromUrl    = item.url;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        if (!objLinkedInFeedRepository.checkLinkedInFeedExists(objLinkedInFeed.FeedId, Guid.Parse(UserId)))
                        {
                            objLinkedInFeedRepository.addLinkedInFeed(objLinkedInFeed);
                        }
                    }
                    #endregion


                    #region Add LinkedIn UserUpdates
                    GlobusLinkedinLib.App.Core.LinkedInUser l = new GlobusLinkedinLib.App.Core.LinkedInUser();
                    List <Domain.Myfashion.Domain.LinkedIn_Update_Messages> lst_Messages = l.GetUserUpdateNew(_oauth, objLinkedInAccount.LinkedinUserId, 10);
                    foreach (var item_Messages in lst_Messages)
                    {
                        try
                        {
                            objLinkedInMessage                 = new Domain.Myfashion.Domain.LinkedInMessage();
                            objLinkedInMessage.Id              = Guid.NewGuid();
                            objLinkedInMessage.Message         = item_Messages.Message;
                            objLinkedInMessage.ProfileId       = item_Messages.ProfileId;
                            objLinkedInMessage.ProfileName     = item_Messages.ProfileName;
                            objLinkedInMessage.CreatedDate     = Convert.ToDateTime(item_Messages.CreatedDate);
                            objLinkedInMessage.EntryDate       = DateTime.Now;
                            objLinkedInMessage.Type            = item_Messages.Type;
                            objLinkedInMessage.UserId          = Guid.Parse(UserId);
                            objLinkedInMessage.ImageUrl        = item_Messages.ImageUrl;
                            objLinkedInMessage.FeedId          = item_Messages.FeedId;
                            objLinkedInMessage.ProfileUrl      = item_Messages.ProfileUrl;
                            objLinkedInMessage.Comments        = item_Messages.Comments;
                            objLinkedInMessage.Likes           = item_Messages.Likes;
                            objLinkedInMessage.ProfileImageUrl = item_Messages.ProfileImageUrl;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        if (!objLinkedInMessageRepository.checkLinkedInMessageExists(objLinkedInAccount.LinkedinUserId, objLinkedInMessage.FeedId, Guid.Parse(UserId)))
                        {
                            objLinkedInMessageRepository.addLinkedInMessage(objLinkedInMessage);
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }
                return("");
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return("");
            }
        }
예제 #8
0
        private void Page_Load(object sender, EventArgs e)
        {
            string url = "";

            _callType = Request.QueryString["type"];

            if (_callType == "facebook")
            {
                //Get the access token.
                _keyString              = Request.QueryString["state"];
                _receivedClubId         = _keyString.Split('-')[2];
                _receivedCacheKeyPrefix = _keyString.Split('-')[0];
                oFace.AccessTokenGet(Request["code"], _keyString);
                if (oFace.Token.Length > 0)
                {
                    _facebookToken   = oFace.Token;
                    _tokenToBeCached = oFace.Token;
                    //We now have the short lived token, need to get long lived token
                }
            }


            if (_callType == "twitter")
            {
                _keyString              = Request.QueryString["state"];
                _receivedClubId         = _keyString.Split('-')[2];
                _receivedCacheKeyPrefix = _keyString.Split('-')[0];
                _receivedNonce          = _keyString.Split('-')[1];
                _twitterSecretKey       = _twitterSecretKeyPrefix + "-" + _receivedNonce + "-" + _receivedClubId;            //Twitter Secret must be cached so it can be received by social_networking_push
                //uses same random nonce that was provided by caller - now caller knows key
                _tempToken = Request.QueryString["oauth_token"];
                _tempToken = Request["oauth_token"].ToString();

                //Get the access token and secret.
                _twitterVerifier = Request["oauth_verifier"].ToString();
                oTwitter.AccessTokenGet(_tempToken, _twitterVerifier);
                if (oTwitter.Token.Length > 0)
                {
                    _twitterToken    = oTwitter.Token;
                    _twitterSecret   = oTwitter.TokenSecret;
                    _tokenToBeCached = oTwitter.Token;
                    //We now have the credentials, so we can start making API calls
                }
            }
            //LinkedIn does not support additional Query parameters, so prefix/key had to be stored in "state" parameter. If we hit this page without a type, it's linkedin.
            if (string.IsNullOrEmpty(_callType))
            {
                _keyString = Request["state"];
                if (!String.IsNullOrEmpty(_keyString))
                {
                    _receivedClubId         = _keyString.Split('-')[2];
                    _receivedCacheKeyPrefix = _keyString.Split('-')[0];
                }
            }

            if (_receivedCacheKeyPrefix == _linkedInCacheKeyPrefix)
            {
                string linkedinCode = Request["code"];
                if (!String.IsNullOrEmpty(linkedinCode))
                {
                    oLinkedIn.AccessTokenGet(linkedinCode);
                    if (oLinkedIn.Token.Length > 0)
                    {
                        _linkedInToken   = oLinkedIn.Token;
                        _tokenToBeCached = oLinkedIn.Token;
                        //We now have the credentials, so we can start making API calls
                    }
                }
            }

            cacheTokens();
        }