Dev Help
Log out
Realtime User Scoring/Profiling
.NET Example
The API can be called from any .NET project (web, forms, console, etc.). The following is an example console application that demonstrates how to make the calls in .NET.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Net; using System.IO; namespace ConsoleApplication1 { public class Class1 { // The user scoring/profiling endpoint. public const string API_URL = "https://gatorapi.com/v1/score"; static void Main(string[] args) { Class1.CreateObject(); } private static void CreateObject() { // To use the API in production, create an account and get an access token from the website. Then assign it to the accessToken variable below. Calls // without an access token will be rate limited. string accessToken = ""; // change this to an access token for production use // set up the parameters for the API call string ip = "72.203.234.33"; // The I.P. address of the user // the user agent of the user, if known string ua = "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"; // the url of the request to your platform string url = "http://www.mysite.com?utm_campaign=BingAds"; // the referrer of the request to your platform - this could be in the HTTP_REFERER header of the request string referrer = "http://bing.com/search?q=car"; // encode the request parameters string query = API_URL + "?accessToken=" + accessToken + "&ip=" + ip + "&ua=" + HttpUtility.UrlEncode(ua) + "&url=" + HttpUtility.UrlEncode(url) + "&referrer=" + HttpUtility.UrlEncode(referrer); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query); request.Method = "GET"; try { WebResponse webResponse = request.GetResponse(); using (Stream webStream = webResponse.GetResponseStream()) { if (webStream != null) { using (StreamReader responseReader = new StreamReader(webStream)) { string response = responseReader.ReadToEnd(); Console.Out.WriteLine(response); } } } } catch (Exception e) { Console.Out.WriteLine(e.Message); } } } }