Skip to content

Real Time Subscriptions with the WebAPI

Damian Green edited this page Jul 24, 2014 · 2 revisions

It's not immediately clear what format to respond to Instagram with. To respond to a subscription challenge get request the following code works:

  public class InstagramController : ApiController
...
     /// <summary>
        /// In order to verify the subscription, your server must respond to the GET request with the hub.challenge parameter only:
        /// </summary>
        /// <returns></returns>
        // GET api/<controller>
        public HttpResponseMessage Get([FromUri(Name = "hub.mode")]string hubMode, [FromUri(Name = "hub.challenge")]string hubChallenge)
        {
            var result =  hubMode == null || hubMode != "subscribe" || hubChallenge == null ? "" : hubChallenge;
            Debug.WriteLine("HandleInstagramHubChallenge " + result);
            var resp = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(result, Encoding.UTF8, "text/plain")
            };
            return resp;
        }
Clone this wiki locally