Exemple #1
0
        public async Task Post(MessageOptions messageOptions, Dictionary <string, string> providerParams)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls12;
            string authCode = null;

            foreach (var param in providerParams)
            {
                if (param.Key == Name)
                {
                    authCode = param.Value;
                }
            }

            var config = new LinkedInApiConfiguration(_options.AppId, _options.AppSecret);
            var api    = new LinkedInApi(config);

            if (authCode != null)
            {
                var accessTokenResult = await api.OAuth2.GetAccessTokenAsync(authCode, _options.RedirectUrl);

                var accessToken = accessTokenResult.AccessToken;
                var requestUrl  = $"https://api.linkedin.com/v2/shares?oauth2_access_token={accessToken}";
                PostToLinkedIn(requestUrl, messageOptions);
            }
        }
Exemple #2
0
        // http://davideguida.altervista.org/mvc-reading-linkedin-user-profile-data/
        // https://github.com/SparkleNetworks/LinkedInNET

        //public RedirectResult Profile()
        //{
        //    var redirectUrl = "http://mydomain/linkedin/profilereturn/";
        //    var url = GetAuthorizationUrl(redirectUrl);
        //    return Redirect(url.ToString());
        //}

        private static LinkedInApi CreateAPI()
        {
            var config = new LinkedInApiConfiguration("77ck1ulnz4e5yh", "olqES8j6K3uXJMNg");
            var api    = new LinkedInApi(config);

            return(api);
        }
Exemple #3
0
        /// <summary>
        /// Authenitcate API from
        /// </summary>
        /// <param name="LinkedInClientId"></param>
        /// <param name="LinkedInClientSecret"></param>
        /// <returns></returns>
        public LinkedInApi ConfigLinkedInAPI(string linkedInClientId, string linkedInClientSecret)
        {
            var config = new LinkedInApiConfiguration(linkedInClientId, linkedInClientSecret);
            var api    = new LinkedInApi(config);

            return(api);
        }
Exemple #4
0
        public LinkedInService()
        {
            // create a configuration object
            var config = new LinkedInApiConfiguration("811365ndnikk36", "hpqB5j5i6HAnZ93Y");

            // get the APIs client
            linkedInAPI = new LinkedInApi(config);
        }
 public void Works()
 {
     var target = new LinkedInApiConfiguration();
     Assert.IsNull(target.ApiKey);
     Assert.IsNull(target.ApiSecretKey);
     Assert.IsNotNull(target.BaseApiUrl);
     Assert.IsNotNull(target.BaseOAuthUrl);
     Assert.AreEqual("https://api.linkedin.com", target.BaseApiUrl);
     Assert.AreEqual("https://www.linkedin.com", target.BaseOAuthUrl);
 }
            public void Works()
            {
                var target = new LinkedInApiConfiguration();

                Assert.IsNull(target.ApiKey);
                Assert.IsNull(target.ApiSecretKey);
                Assert.IsNotNull(target.BaseApiUrl);
                Assert.IsNotNull(target.BaseOAuthUrl);
                Assert.AreEqual("https://api.linkedin.com", target.BaseApiUrl);
                Assert.AreEqual("https://www.linkedin.com", target.BaseOAuthUrl);
            }
Exemple #7
0
            public void Works()
            {
                AuthorizationScope scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress;
                string state = "AZERTYUIOP";
                string redirectUri = "http://localhost/Callbacks/LinkedIN?Redirect=" + Uri.EscapeDataString("/Profile?LinkedIN");

                var config = new LinkedInApiConfiguration { ApiKey = "HELLOAPI", BaseOAuthUrl = "https://linkedin.com", };
                var api = new LinkedInApi(config);

                var result = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUri);
                Assert.AreEqual("https://linkedin.com/uas/oauth2/authorization?response_type=code&client_id=HELLOAPI&scope=r_basicprofile%20r_emailaddress&state=AZERTYUIOP&redirect_uri=http%3A%2F%2Flocalhost%2FCallbacks%2FLinkedIN%3FRedirect%3D%252FProfile%253FLinkedIN", result.OriginalString);
            }
        private static LinkedInApiConfiguration FromAppSettings(string prefix)
        {
            if (prefix != null)
            {
                if (!prefix.EndsWith("."))
                    prefix += ".";
            }

            var me = new LinkedInApiConfiguration();
            me.ApiKey = ConfigurationManager.AppSettings[prefix + "ApiKey"];
            me.ApiSecretKey = ConfigurationManager.AppSettings[prefix + "ApiSecretKey"];

            return me;
        }
Exemple #9
0
            public void Works()
            {
                AuthorizationScope scope       = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress;
                string             state       = "AZERTYUIOP";
                string             redirectUri = "http://localhost/Callbacks/LinkedIN?Redirect=" + Uri.EscapeDataString("/Profile?LinkedIN");

                var config = new LinkedInApiConfiguration {
                    ApiKey = "HELLOAPI", BaseOAuthUrl = "https://linkedin.com",
                };
                var api = new LinkedInApi(config);

                var result = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUri);

                Assert.AreEqual("https://linkedin.com/uas/oauth2/authorization?response_type=code&client_id=HELLOAPI&scope=r_basicprofile%20r_emailaddress&state=AZERTYUIOP&redirect_uri=http%3A%2F%2Flocalhost%2FCallbacks%2FLinkedIN%3FRedirect%3D%252FProfile%253FLinkedIN", result.OriginalString);
            }
    protected void cbLinkedIn_CheckedChanged(object sender, EventArgs e)
    {
        bool isChecked = cbLinkedIn.Checked;

        if (isChecked)
        {
            string requestCode = string.Empty;
            if (Session[LinkedInCodeSessionKey] == null)
            {
                Session[MessageKey] = txtFeedContent.Text.Trim();
                //Session[TitleKey] = txtTitle.Text.Trim();
                Session[ShareCodeType]   = "LinkedIn";
                Session[CurrentResultID] = hdnSelectedMessageID.Value;
                Session[CurrentMessage]  = lblPostTitle.Text.Trim();

                var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);

                // get the APIs client
                var api = new LinkedInApi(config);

                string queryString = Request.Url.Query;

                string redirectUrl = Request.Url.AbsoluteUri;
                if (queryString.Trim() != string.Empty)
                {
                    redirectUrl = redirectUrl.Replace(queryString, string.Empty);
                }

                var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress | AuthorizationScope.WriteShare | AuthorizationScope.ReadWriteCompanyPage;
                var state = Guid.NewGuid().ToString();
                var url   = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);

                Response.Redirect(url.AbsoluteUri, false);
            }
        }
        else
        {
            Session.Remove(LinkedInCodeSessionKey);
            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
                Response.Redirect(redirectUrl);
            }
        }
    }
Exemple #11
0
        private static LinkedInApiConfiguration FromAppSettings(string prefix)
        {
            if (prefix != null)
            {
                if (!prefix.EndsWith("."))
                {
                    prefix += ".";
                }
            }

            var me = new LinkedInApiConfiguration();

            me.ApiKey       = ConfigurationManager.AppSettings[prefix + "ApiKey"];
            me.ApiSecretKey = ConfigurationManager.AppSettings[prefix + "ApiSecretKey"];

            return(me);
        }
Exemple #12
0
        public static async Task PublishMessage(string text, string imageUrl = null)
        {
            var config = new LinkedInApiConfiguration(SendTweet.Configuration["linkedInApiKey"], SendTweet.Configuration["linkedInApiKeySecret"]);
            var api    = new LinkedInApi(config);

            var user = new UserAuthorization(accessToken);

            try
            {
                await api.Shares.PostAsync(user, new PostShare()
                {
                    Owner   = $"urn:li:person:{SendTweet.Configuration["linkedInUserId"]}",
                    Subject = "Azure Lowlands",
                    Text    = new PostShareText()
                    {
                        Text = "Remember, the full line-up for #AzureLowlands is available now, so check https://azurelowlands.com for all details and get your FREE tickets today!"
                    }
                });
            }
            catch (Exception exception)
            {
                var temp = exception;
            }

            /*await api.UGCPost.PostAsync(user, new UGCPostData()
             * {
             *  Author = $"urn:li:person:{SendTweet.Configuration["linkedInUserId"]}",
             *  LifecycleState = "PUBLISHED",
             *  Visibility = new UGCPostvisibility()
             *  {
             *      comLinkedinUgcMemberNetworkVisibility = "PUBLIC"
             *  },
             *  SpecificContent = new SpecificContent()
             *  {
             *      ComLinkedinUgcShareContent = new ComLinkedinUgcShareContent()
             *      {
             *          ShareCommentary = new UGCText()
             *          {
             *              Text = "Remember, the full line-up for #AzureLowlands is available now, so check https://azurelowlands.com for all details and get your FREE tickets today!"
             *          },
             *          ShareMediaCategory = "NONE"
             *      }
             *  }
             * });*/
        }
 public HomeController(LinkedInApi api, DataService data, LinkedInApiConfiguration apiConfig)
 {
     this.api       = api;
     this.data      = data;
     this.apiConfig = apiConfig;
 }
    private bool PostLinkedIn()
    {
        string requestCode = Session[LinkedInCodeSessionKey].ToString();

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            //Session[TitleKey] = txtTitle.Text.Trim();

            var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
            var api    = new LinkedInApi(config);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress | AuthorizationScope.WriteShare | AuthorizationScope.ReadWriteCompanyPage;
            var state = Guid.NewGuid().ToString();
            var url   = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);

            Response.Redirect(url.AbsoluteUri, false);
        }
        else
        {
            int linkedInCompanyID = int.Parse(LinkedInCompanyID);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            try
            {
                string message = txtFeedContent.Text.Trim();

                var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
                // get the APIs client
                var api = new LinkedInApi(config);
                AuthorizationAccessToken userToken = api.OAuth2.GetAccessToken(requestCode, redirectUrl);

                if (userToken != null)
                {
                    string   acessToken           = userToken.AccessToken;
                    DateTime authorizationDateUTC = userToken.AuthorizationDateUtc;
                    int?     expiresIn            = userToken.ExpiresIn;

                    AccessTokenController accessTokenController = new AccessTokenController();
                    int addUpdateResult = accessTokenController.AddLinkedInAccessToken(acessToken, authorizationDateUTC, expiresIn);
                }

                UserAuthorization user = new UserAuthorization(userToken.AccessToken);

                PostShareResult postShareResult = api.Companies.Share(
                    user,
                    linkedInCompanyID, new PostShare()
                {
                    Visibility = new Visibility()
                    {
                        Code = "anyone"
                    },
                    Comment = message
                });

                string resultID = hdnSelectedMessageID.Value;
                SocialFeedController feedController = new SocialFeedController();
                UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(postShareResult.Location, postShareResult.UpdateKey, postShareResult.UpdateUrl, message, resultID);

                int output = feedController.SaveUserChoice(userChoiceInfo);

                if (output == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }

        return(false);
    }
 public ExploreController(LinkedInApi api, DataService data, LinkedInApiConfiguration apiConfig)
 {
     this.api = api;
     this.data = data;
     this.apiConfig = apiConfig;
 }