/// <summary> /// Makes a call to the Instagram API to exchange the specified <paramref name="authCode"/> for an access token. /// </summary> /// <param name="authCode">The authorization code obtained from an OAuth 2.0 login flow.</param> /// <returns>An instance of <see cref="InstagramTokenResponse"/> representing the response from the server.</returns> public virtual InstagramTokenResponse GetAccessTokenFromAuthCode(string authCode) { // Some validation if (String.IsNullOrWhiteSpace(ClientId)) { throw new PropertyNotSetException("ClientId"); } if (String.IsNullOrWhiteSpace(ClientSecret)) { throw new PropertyNotSetException("ClientSecret"); } if (String.IsNullOrWhiteSpace(RedirectUri)) { throw new PropertyNotSetException("RedirectUri"); } if (String.IsNullOrWhiteSpace(authCode)) { throw new ArgumentNullException("authCode"); } // Initialize collection with POST data IHttpPostData parameters = new SocialHttpPostData(); parameters.Add("client_id", ClientId); parameters.Add("client_secret", ClientSecret); parameters.Add("grant_type", "authorization_code"); parameters.Add("redirect_uri", RedirectUri); parameters.Add("code", authCode); // Make the call to the API SocialHttpResponse response = SocialUtils.Http.DoHttpPostRequest("https://api.instagram.com/oauth/access_token", null, parameters); // Parse the response return(InstagramTokenResponse.ParseResponse(response)); }
public void SaveInstagramUser(InstagramTokenResponse userResponse) { InstagramTokenResponse = userResponse; _settingsService.Set(Constants.Settings.InstagramUser, InstagramTokenResponse); _settingsService.Save(); }