public ActionResult InstagramReturnUrl(string code) { InstagramAuth instagramAuth = new InstagramAuth(); OuthUser user = instagramAuth.GetAccessToken(code, instaConfig); // get user who loged in with an access_token string access_token = user.access_token; Likes likes = new Likes(); string idImage = "1476852486660100934_2015123882"; likes.LikeMedia(idImage, access_token); return(View()); }
public OuthUser GetAccessToken(string code, InstaConfig ic) { var client = new HttpClient(); var postData = new List <KeyValuePair <string, string> >(); postData.Add(new KeyValuePair <string, string>("client_id", ic.client_id)); postData.Add(new KeyValuePair <string, string>("client_secret", ic.client_secret)); postData.Add(new KeyValuePair <string, string>("grant_type", "authorization_code")); postData.Add(new KeyValuePair <string, string>("redirect_uri", ic.redirect_uri)); postData.Add(new KeyValuePair <string, string>("code", code)); HttpContent content = new FormUrlEncodedContent(postData); var rslt = client.PostAsync("https://api.instagram.com/oauth/access_token", content).Result; var result = rslt.Content.ReadAsStringAsync().Result; OuthUser aa = JsonConvert.DeserializeObject <OuthUser>(result); return(aa); }