Sunday, 8 November 2015

Create Yozio SubLink using C#

If you need to read more about Yozio Sublink API, here is the documentation http://docs.yozio.com/articles/sublink-apis

Below is a code to create Yozio Sublink.
using System;
using System.Net;
using Newtonsoft.Json;

namespace Yozio
{
    public class YozioResult
    {
        public string status { get; set; }
        public Body body { get; set; }
    }
 
    public class Body
    {
        public string sub_link { get; set; }
        public object link_alias { get; set; }
        public MetaData meta_data { get; set; }
        public long timestamp { get; set; }
    }
 
    public class MetaData
    {
        public string utm_source { get; set; }
        public string utm_medium { get; set; }
        public string utm_campaign { get; set; }
    }
 
    public static class YozioApi
    {
        public static YozioResult SubLink
        {
            get
            {
                const string apiKey = "YOUR-YOZIO-API-KEY";
                const string yozioSuperLink = "YOZIO-SUPER-LINK"; //e.gk7.k.cf

                const string urlString = "http://api.yozio.com/v2.0/?app_key={0}&" +
                                         "method=sub.link.create&" +
                                         "short_url={1}&" +
                                         "reassign_old_alias_to_this_link=true&" +
                                         "meta_data[utm_source]=web&" +
                                         "meta_data[utm_medium]=link&" +
                                         "meta_data[utm_campaign]=blog";

                var url = string.Format(urlString, apiKey, yozioSuperLink);

                var client = new WebClient();
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                var json = client.DownloadString(new Uri(url));
                var result = JsonConvert.DeserializeObject<yozioresult>(json);
                return result;
            }
        }
    }
}
Usage: Getting Sublink
Yozio.YozioApi.SubLink.body.sub_link;

/Adnan

About the Author

Adnan Zameer, Lead Developer at Optimizley UK, is a certified Microsoft professional, specializing in web app architecture. His expertise includes Optimizley CMS and Azure, showcasing proficiency in crafting robust and efficient solutions.

0 comments :

Post a Comment