/// <summary> /// This will display the user payload returned from Engage /// </summary> /// <param name="User" type="EngageService">Represents the returned user profile</param> public void ShowUserData(EngageUser User) { //Make our display containers visible BodyContainer.Visible = true; EngageProvider.Visible = true; EngageAccessToken.Visible = true; EngageUserName.Visible = true; EngageEmail.Visible = true; EngageIdentifier.Visible = true; EngageFirstName.Visible = true; EngageLastName.Visible = true; if (User.Photo != null) { EngagePhoto.Visible = true; } // Get Profile Data and show on page EngageProvider.InnerHtml += User.Provider; EngageAccessToken.InnerHtml += User.ProviderAccessToken; EngageUserName.InnerHtml += User.UserName; EngageEmail.InnerHtml += User.Email; EngageIdentifier.InnerHtml += User.Identifier; EngageFirstName.InnerHtml += User.FirstName; EngageLastName.InnerHtml += User.LastName; HeaderName.Text = User.FirstName + " " + User.LastName; if (User.Photo != null) { UserPhoto.ImageUrl = User.Photo; } }
/// <summary> /// Get the list of contacts from a users selected provider /// </summary> /// <param name="User">The authenticated Engage User object</param> /// <returns>An XmlDocument object from Engage</returns> public XmlDocument GetUserContacts(EngageUser User) { XmlDocument contacts = EngageService.GetContacts(Server.HtmlEncode(User.Identifier)); return(contacts); }
/// <summary> /// This will display the user payload returned from Engage /// </summary> /// <param name="User" type="EngageService">Represents the returned user profile</param> public void ShowUserData(EngageUser User) { //Make our display containers visible BodyContainer.Visible = true; EngageProvider.Visible = true; EngageAccessToken.Visible = true; EngageUserName.Visible = true; EngageEmail.Visible = true; EngageIdentifier.Visible = true; EngageFirstName.Visible = true; EngageLastName.Visible = true; if (User.Photo != null) EngagePhoto.Visible = true; // Get Profile Data and show on page EngageProvider.InnerHtml += User.Provider; EngageAccessToken.InnerHtml += User.ProviderAccessToken; EngageUserName.InnerHtml += User.UserName; EngageEmail.InnerHtml += User.Email; EngageIdentifier.InnerHtml += User.Identifier; EngageFirstName.InnerHtml += User.FirstName; EngageLastName.InnerHtml += User.LastName; HeaderName.Text = User.FirstName + " " + User.LastName; if (User.Photo != null) UserPhoto.ImageUrl = User.Photo; }
/// <summary> /// Get the list of contacts from a users selected provider /// </summary> /// <param name="User">The authenticated Engage User object</param> /// <returns>An XmlDocument object from Engage</returns> public XmlDocument GetUserContacts(EngageUser User) { XmlDocument contacts = LocalEngageService.GetContacts(Server.HtmlEncode(User.Identifier)); return contacts; }
/// <summary> /// Get the user profile data from the Engage Service /// </summary> /// <param name="Token">String representing token posted from Engage service</param> /// <returns></returns> public EngageUser AuthInfo(string Token) { //build parameters to make the call string parameters = "token=" + Token + "&apiKey=" + this.apiKey + "&format=xml"; //create the URI string uri = baseUrl + "auth_info"; //make the web request WebRequest engageRequest = WebRequest.Create(uri); engageRequest.ContentType = "application/x-www-form-urlencoded"; engageRequest.Method = "POST"; byte[] bytes = Encoding.ASCII.GetBytes(parameters); Stream requestStream = null; //Post the request to the auth_info REST web service try { engageRequest.ContentLength = bytes.Length; //Count bytes to send requestStream = engageRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); //Send it } catch (WebException ex) { //Handle WebException error here return null; } finally { if (requestStream != null) { requestStream.Close(); } } //Get the response from the auth_info REST web service try { //If there's a web response, then read the stream...otherwise exit the flow WebResponse engageResponse = engageRequest.GetResponse(); if (engageResponse == null) { return null; } StreamReader engageStream = new StreamReader(engageResponse.GetResponseStream()); //Create an XML Document and apply our returned payload to the object XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(engageStream.ReadToEnd().Trim()); XmlElement documentElement = doc.DocumentElement; //Engage error check. There are 2 possible conditions, either an empty object OR "stat" not equally OK if (documentElement == null || !documentElement.GetAttribute("stat").Equals("ok")) { // TODO: Handle Unexpected errors // throw new Exception("Unexpected API error"); } EngageUser User = new EngageUser(documentElement); return User; } catch (WebException ex) { //Handle WebException error here return null; } }
/// <summary> /// Get the user profile data from the Engage Service /// </summary> /// <param name="Token">String representing token posted from Engage service</param> /// <returns></returns> public EngageUser AuthInfo(string Token) { //build parameters to make the call string parameters = "token=" + Token + "&apiKey=" + this.apiKey + "&format=xml"; //create the URI string uri = baseUrl + "auth_info"; //make the web request WebRequest engageRequest = WebRequest.Create(uri); engageRequest.ContentType = "application/x-www-form-urlencoded"; engageRequest.Method = "POST"; byte[] bytes = Encoding.ASCII.GetBytes(parameters); Stream requestStream = null; //Post the request to the auth_info REST web service try { engageRequest.ContentLength = bytes.Length; //Count bytes to send requestStream = engageRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); //Send it } catch (WebException ex) { //Handle WebException error here return(null); } finally { if (requestStream != null) { requestStream.Close(); } } //Get the response from the auth_info REST web service try { //If there's a web response, then read the stream...otherwise exit the flow WebResponse engageResponse = engageRequest.GetResponse(); if (engageResponse == null) { return(null); } StreamReader engageStream = new StreamReader(engageResponse.GetResponseStream()); //Create an XML Document and apply our returned payload to the object XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml(engageStream.ReadToEnd().Trim()); XmlElement documentElement = doc.DocumentElement; //Engage error check. There are 2 possible conditions, either an empty object OR "stat" not equally OK if (documentElement == null || !documentElement.GetAttribute("stat").Equals("ok")) { // TODO: Handle Unexpected errors // throw new Exception("Unexpected API error"); } EngageUser User = new EngageUser(documentElement); return(User); } catch (WebException ex) { //Handle WebException error here return(null); } }
protected void Page_Load(object sender, EventArgs e) { string TokenValue = Request["token"]; //Get token returned from Engage string ApiKey = "8c04fd573bd8d27d5ec72eda1d04c5f82909c6c6"; //Unique Engage API Key string EngageAppURL = "https://jbtest.rpxnow.com/openid/v2/signin?token_url="; //The Engage Application URL that you get from the Sign in Setup string EngageTokenURL = "http%3A%2F%2Flocalhost%2Fengagedotnet%2Fdefault.aspx"; //The URL Encoded token URL that you get from the Sign in Setup bool ShowContactsFlag = true; //To show the contacts for this user based on the network that they logged in with bool SendStatusUpdate = false; //To show an API level social publish using default "canned" data string ContactProviders = "Facebook,Google,LinkedIn"; //This is the list of providers that you can get contacts from EngageSignInLink.HRef = EngageAppURL + EngageTokenURL; //Full signin link to start the sign in process //For this starter, the Default.aspx page is the initiating page AND the token URL //So, we must check to see if there's a token that's being posted or not if (TokenValue != null) { LocalEngageService = new EngageService(ApiKey); //Get the user profile based on the returned token. EngageUser User = GetUserData(TokenValue); //Show the user data if (User != null) { ShowUserData(User); } #region Social Publishing API //Make an API level wall update. Use with Facebook as best example! //NOTE: This uses a pre-formatted JSON object pulled from documentation on rpxnow.com/docs#api_activity. Clearly you would want to format //this according to REAL data. /* * { * "user_generated_content": "I thought you would appreciate my review.", * "title": "A Critique of Atomic Pizza", * "action_links": [ * { * "href": "http:\/\/example.com\/review\/write", * "text": "Write a review" * } * ], * "action": "wrote a review of Atomic Pizza", * "url": "http:\/\/example.com\/reviews\/12345\/", * "media": [ * { * "href": "http:\/\/bit.ly\/3fkBwe", * "src": "http:\/\/bit.ly\/1nmIX9", * "type": "image" * } * ], * "description": "Atomic Pizza has a great atmosphere and great prices.", * "properties": { * "Location": { * "href": "http:\/\/bit.ly\/3fkBwe", * "text": "North Portland" * }, * "Rating": "5 Stars" * } * } */ #endregion if (SendStatusUpdate) { string StatusMessage = "{\"user_generated_content\": \"I thought you would appreciate my review.\",\"title\": \"A Critique of Atomic Pizza\",\"action_links\": [{\"href\": \"http:\\/\\/example.com\\/review\\/write\",\"text\": \"Write a review\"}],\"action\": \"wrote a review of Atomic Pizza\",\"url\": \"http:\\/\\/example.com\\/reviews\\/12345\\/\",\"media\": [{\"href\": \"http:\\/\\/bit.ly\\/3fkBwe\",\"src\": \"http:\\/\\/bit.ly\\/1nmIX9\",\"type\": \"image\"}],\"description\": \"Atomic Pizza has a great atmosphere and great prices.\",\"properties\": {\"Location\": {\"href\": \"http:\\/\\/bit.ly\\/3fkBwe\",\"text\": \"North Portland\"},\"Rating\": \"5 Stars\"}}"; LocalEngageService.SetActivity(User.Identifier, StatusMessage); } //Get Contacts for the user based on page setup if (ShowContactsFlag) { //If the provider in the list of providers matches the provider that the user logged in with then //get the contacts for that provider string[] providerList = ContactProviders.Split(','); foreach (string specificProvider in providerList) { if (User.Provider == specificProvider) { ShowContacts(GetUserContacts(User)); break; } } } } }
static void Main(string[] args) { Console.WriteLine("\nWelcome to Engage Tracker sample app."); if (args.Length != 3) { Console.WriteLine("!! Please provide mandatory arguments for organisationId, productId and the eventUrl"); Console.WriteLine("$ dotnet run <organisationId> <productId> <eventUrl>\n"); Environment.Exit(0); } var organisationId = args[0]; var productId = args[1]; var eventUrl = args[2]; EngageStorage storage = new EngageStorage(new MemoryStorageService()); EngageApplication application = new EngageApplication(new CliApplicationService()); var tracker = EngageTrackerBuilder.Build(organisationId, productId, eventUrl, storage, application); var user = new EngageUser { UserId = Util.GenerateGuid(), PaywayUserId = Util.GenerateGuid(), Products = new string[] { "product_1", "product_2" }, LoggedIn = true, Position = new EngageUserLocation { Latitude = "10", Longitude = "20" }, }; tracker.SaveUser(user); var eventBuilder = new EngageEventBuilder(storage, application); var trackEvent = eventBuilder.Build("app:pageview"); tracker.Track("/", trackEvent); var artEvent = eventBuilder.Build("app:article.read"); tracker.Track("/", artEvent); var content = new EngageContent { State = "open", Type = "paid", ArticleId = Util.GenerateGuid(), Title = "Long title noone wants to read", Section = "Sport", Keywords = new string[] { "sport", "news" }, AuthorId = new string[] { Util.GenerateGuid() }, Location = new EngageArticleLocation { Latitude = "10", Longitude = "20" } }; var purchaseEvent = eventBuilder.Build("app:article.purchase"); purchaseEvent.Content = content; var newUser = new EngageUser { UserId = "other-user-id", PaywayUserId = "other-payway-id", Products = new string[] { "product_1", "product_2", "product_3" }, LoggedIn = true, Position = new EngageUserLocation { Latitude = "10", Longitude = "20" }, }; purchaseEvent.User = newUser; var source = eventBuilder.Source(); source.Browser.Name = "Test CLI"; source.Locale.Language = "sv"; source.Locale.TimeZoneOffset = "+1"; purchaseEvent.Source = source; tracker.Track("/purchase", purchaseEvent); }
public void SaveUser(EngageUser user) { _storage.User = user; }