From 266624a30c805e6fc309086da110a9467141eae4 Mon Sep 17 00:00:00 2001 From: Arzhang Mosaffa Date: Wed, 26 Sep 2018 06:30:18 +0330 Subject: [PATCH 1/3] implemented challenge resolving --- InstaSharper/API/IInstaApi.cs | 27 ++++ InstaSharper/API/InstaApi.cs | 129 +++++++++++++++++- InstaSharper/API/InstaApiConstants.cs | 10 +- .../Classes/InstaLoginBaseResponse.cs | 11 +- InstaSharper/Classes/InstaLoginResult.cs | 1 + InstaSharper/Classes/ResponseType.cs | 3 +- .../Classes/ResponseWrappers/FbLocation.cs | 25 ++++ .../Classes/ResponseWrappers/FbPlace.cs | 20 +++ .../ResponseWrappers/FbSearchPlaceResponse.cs | 16 +++ .../ResponseWrappers/InstaChallenge.cs | 19 +++ .../Classes/ResponseWrappers/InstaNametag.cs | 20 +++ .../ResponseWrappers/InstaResetChallenge.cs | 23 ++++ .../Classes/ResponseWrappers/InstaStepData.cs | 19 +++ .../ResponseWrappers/InstaUserResponse.cs | 33 ++++- InstaSharper/Classes/Result.cs | 3 + InstaSharper/Helpers/UriCreator.cs | 26 +++- 16 files changed, 372 insertions(+), 13 deletions(-) create mode 100644 InstaSharper/Classes/ResponseWrappers/FbLocation.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/FbPlace.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/FbSearchPlaceResponse.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/InstaChallenge.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/InstaNametag.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/InstaResetChallenge.cs create mode 100644 InstaSharper/Classes/ResponseWrappers/InstaStepData.cs diff --git a/InstaSharper/API/IInstaApi.cs b/InstaSharper/API/IInstaApi.cs index 4367a98a..8e94d2ec 100644 --- a/InstaSharper/API/IInstaApi.cs +++ b/InstaSharper/API/IInstaApi.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using InstaSharper.Classes; using InstaSharper.Classes.Models; +using InstaSharper.Classes.ResponseWrappers; namespace InstaSharper.API { @@ -52,6 +53,32 @@ public interface IInstaApi /// Task> LoginAsync(); + /// + /// Search Place + /// + Task> SearchPlace(string searchQuery, int count = 5); + + + /// + /// Reset challenge asynchronously + /// + Task> ResetChallenge(); + + /// + /// Get verify method asynchronously + /// + Task> GetVerifyStep(); + + /// + /// Choose verify method asynchronously + /// + Task> ChooseVerifyMethod(int choice); + + /// + /// Send verify code asynchronously + /// + Task> SendVerifyCode(string securityCode); + /// /// 2-Factor Authentication Login using a verification code /// Before call this method, please run LoginAsync first. diff --git a/InstaSharper/API/InstaApi.cs b/InstaSharper/API/InstaApi.cs index 39ea2e54..13569a65 100644 --- a/InstaSharper/API/InstaApi.cs +++ b/InstaSharper/API/InstaApi.cs @@ -34,6 +34,7 @@ internal class InstaApi : IInstaApi private IStoryProcessor _storyProcessor; private TwoFactorLoginInfo _twoFactorInfo; + private InstaChallenge _challengeInfo; private UserSessionData _user; private IUserProcessor _userProcessor; @@ -926,7 +927,13 @@ public async Task> LoginAsync() //2FA is required! return Result.Fail("Two Factor Authentication is required", InstaLoginResult.TwoFactorRequired); } - + if (loginFailReason.ChallengeRequired) + { + _challengeInfo = loginFailReason.Challenge; + //Challenge is Required! + return Result.Fail("Challenge is required", InstaLoginResult.ChallengeRequired); + } + return Result.UnExpectedResponse(response, json); } @@ -948,6 +955,126 @@ public async Task> LoginAsync() } } + /// + /// Search Place + /// + public async Task> SearchPlace(string searchQuery, int count) + { + var signature = + $"{_httpRequestProcessor.RequestMessage.GenerateSignature(InstaApiConstants.IG_SIGNATURE_KEY)}" + + $".{_httpRequestProcessor.RequestMessage.GetMessageString()}"; + var fbSeachPlaceUri = UriCreator.GetFbSearchPlace(count, _user.RankToken, searchQuery); + var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, fbSeachPlaceUri, _deviceInfo); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE, signature); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, + InstaApiConstants.IG_SIGNATURE_KEY_VERSION); + var response = await _httpRequestProcessor.SendAsync(request); + var json = await response.Content.ReadAsStringAsync(); + var fbSeachPlaceResponse = JsonConvert.DeserializeObject(json); + return Result.Success(fbSeachPlaceResponse); + } + + /// + /// Reset challenge asynchronously + /// + public async Task> ResetChallenge() + { + var signature = + $"{_httpRequestProcessor.RequestMessage.GenerateSignature(InstaApiConstants.IG_SIGNATURE_KEY)}" + + $".{_httpRequestProcessor.RequestMessage.GetMessageString()}"; + var fields = new Dictionary + { + {InstaApiConstants.HEADER_IG_SIGNATURE, signature}, + {InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, InstaApiConstants.IG_SIGNATURE_KEY_VERSION} + }; + var token = _challengeInfo.ApiPath.Substring(11); + var instaUri = UriCreator.GetResetChallengeUri(token); + var request = HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, _deviceInfo); + request.Content = new FormUrlEncodedContent(fields); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE, signature); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, + InstaApiConstants.IG_SIGNATURE_KEY_VERSION); + var response = await _httpRequestProcessor.SendAsync(request); + var json = await response.Content.ReadAsStringAsync(); + var resetChallengeResponse = JsonConvert.DeserializeObject(json); + return Result.Success(resetChallengeResponse); + } + + /// + /// Get verify method asynchronously + /// + public async Task> GetVerifyStep() + { + var signature = + $"{_httpRequestProcessor.RequestMessage.GenerateSignature(InstaApiConstants.IG_SIGNATURE_KEY)}" + + $".{_httpRequestProcessor.RequestMessage.GetMessageString()}"; + var token = _challengeInfo.ApiPath.Substring(11); + var instaUri = UriCreator.GetVerifyMethod(token); + var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, instaUri, _deviceInfo); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE, signature); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, + InstaApiConstants.IG_SIGNATURE_KEY_VERSION); + var response = await _httpRequestProcessor.SendAsync(request); + var json = await response.Content.ReadAsStringAsync(); + var resetChallengeResponse = JsonConvert.DeserializeObject(json); + return Result.Success(resetChallengeResponse); + } + + /// + /// Choose verify method asynchronously + /// + public async Task> ChooseVerifyMethod(int choice) + { + var signature = + $"{_httpRequestProcessor.RequestMessage.GenerateSignature(InstaApiConstants.IG_SIGNATURE_KEY)}" + + $".{_httpRequestProcessor.RequestMessage.GetMessageString()}"; + var fields = new Dictionary + { + {InstaApiConstants.VEFITY_CHOICE, choice.ToString()}, + }; + var token = _challengeInfo.ApiPath.Substring(11); + var instaUri = UriCreator.GetVerifyMethod(token); + var request = HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, _deviceInfo); + request.Content = new FormUrlEncodedContent(fields); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE, signature); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, + InstaApiConstants.IG_SIGNATURE_KEY_VERSION); + var response = await _httpRequestProcessor.SendAsync(request); + var json = await response.Content.ReadAsStringAsync(); + var resetChallengeResponse = JsonConvert.DeserializeObject(json); + return Result.Success(resetChallengeResponse); + } + + /// + /// Send verify code asynchronously + /// + public async Task> SendVerifyCode(string securityCode) + { + var signature = + $"{_httpRequestProcessor.RequestMessage.GenerateSignature(InstaApiConstants.IG_SIGNATURE_KEY)}" + + $".{_httpRequestProcessor.RequestMessage.GetMessageString()}"; + var fields = new Dictionary + { + {InstaApiConstants.SECURITY_CODE, securityCode.ToString()}, + }; + var token = _challengeInfo.ApiPath.Substring(11); + var instaUri = UriCreator.GetVerifyMethod(token); + var request = HttpHelper.GetDefaultRequest(HttpMethod.Post, instaUri, _deviceInfo); + request.Content = new FormUrlEncodedContent(fields); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE, signature); + request.Properties.Add(InstaApiConstants.HEADER_IG_SIGNATURE_KEY_VERSION, + InstaApiConstants.IG_SIGNATURE_KEY_VERSION); + var response = await _httpRequestProcessor.SendAsync(request); + var json = await response.Content.ReadAsStringAsync(); + if (response.StatusCode != HttpStatusCode.OK ) + { + return Result.Fail("invalid verify code"); + } + var sendVerifyCodeResponse = JsonConvert.DeserializeObject(json); + IsUserAuthenticated = sendVerifyCodeResponse.LoggedInUser?.UserName.ToLower() == _user.UserName.ToLower(); + return Result.Success(sendVerifyCodeResponse); + } + /// /// 2-Factor Authentication Login using a verification code /// Before call this method, please run LoginAsync first. diff --git a/InstaSharper/API/InstaApiConstants.cs b/InstaSharper/API/InstaApiConstants.cs index d6545084..b6655ba1 100644 --- a/InstaSharper/API/InstaApiConstants.cs +++ b/InstaSharper/API/InstaApiConstants.cs @@ -45,7 +45,10 @@ public const string public const string HEADER_XGOOGLE_AD_IDE = "X-Google-AD-ID"; public const string COMMENT_BREADCRUMB_KEY = "iN4$aGr0m"; public const int TIMEZONE_OFFSET = 43200; - + public const string VEFITY_CHOICE = "choice"; + public const string SECURITY_CODE = "security_code"; + + public const string INSTAGRAM_URL = "https://i.instagram.com"; public const string API = "/api"; public const string API_SUFFIX = API + API_VERSION; @@ -73,7 +76,10 @@ public const string public const string GET_USER_FOLLOWING = API_SUFFIX + "/friendships/{0}/following/?rank_token={1}"; public const string GET_TAG_FEED = API_SUFFIX + "/feed/tag/{0}"; public const string GET_RANKED_RECIPIENTS = API_SUFFIX + "/direct_v2/ranked_recipients"; - + public const string RESET_CHALLENGE = API_SUFFIX + "/challenge/reset/{0}"; + public const string VERIFY_METHOD = API_SUFFIX + "/challenge/{0}"; + public const string FB_SEARCH_PLACE = API_SUFFIX + "/fbsearch/places/?count={0}&query={1}&rank_token={2}"; + public const string GET_LIST_COLLECTIONS = API_SUFFIX + "/collections/list/"; public const string GET_COLLECTION = API_SUFFIX + "/feed/collection/{0}/"; public const string CREATE_COLLECTION = API_SUFFIX + "/collections/create/"; diff --git a/InstaSharper/Classes/InstaLoginBaseResponse.cs b/InstaSharper/Classes/InstaLoginBaseResponse.cs index 05b2f449..22846088 100644 --- a/InstaSharper/Classes/InstaLoginBaseResponse.cs +++ b/InstaSharper/Classes/InstaLoginBaseResponse.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using InstaSharper.Classes.ResponseWrappers; +using Newtonsoft.Json; namespace InstaSharper.Classes { @@ -19,5 +20,13 @@ internal class InstaLoginBaseResponse [JsonProperty("two_factor_info")] public TwoFactorLoginInfo TwoFactorLoginInfo { get; set; } #endregion + + #region Challenge Required + + [JsonIgnore] public bool ChallengeRequired => ErrorType == "checkpoint_challenge_required"; + + [JsonProperty("challenge")] public InstaChallenge Challenge { get; set; } + + #endregion } } \ No newline at end of file diff --git a/InstaSharper/Classes/InstaLoginResult.cs b/InstaSharper/Classes/InstaLoginResult.cs index 4ff133eb..965a334b 100644 --- a/InstaSharper/Classes/InstaLoginResult.cs +++ b/InstaSharper/Classes/InstaLoginResult.cs @@ -6,6 +6,7 @@ public enum InstaLoginResult BadPassword, InvalidUser, TwoFactorRequired, + ChallengeRequired, Exception } } \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseType.cs b/InstaSharper/Classes/ResponseType.cs index 1f8e6ea3..a6e3980d 100644 --- a/InstaSharper/Classes/ResponseType.cs +++ b/InstaSharper/Classes/ResponseType.cs @@ -11,6 +11,7 @@ public enum ResponseType WrongRequest = 6, SomePagesSkipped = 7, UnExpectedResponse = 8, - InternalException = 9 + InternalException = 9, + CheckPointChallengeRequired = 10 } } \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/FbLocation.cs b/InstaSharper/Classes/ResponseWrappers/FbLocation.cs new file mode 100644 index 00000000..50ac5225 --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/FbLocation.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class FbLocation + { + [JsonProperty("pk")] public long Pk { get; set; } + + [JsonProperty("name")] public string Name { get; set; } + + [JsonProperty("address")] public string Address { get; set; } + + [JsonProperty("city")] public string City { get; set; } + + [JsonProperty("short_name")] public string ShortName { get; set; } + + [JsonProperty("lng")] public double Lng { get; set; } + + [JsonProperty("lat")] public double Lat { get; set; } + + [JsonProperty("external_source")] public string ExternalSource { get; set; } + + [JsonProperty("facebook_places_id")] public object FacebookPlacesId { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/FbPlace.cs b/InstaSharper/Classes/ResponseWrappers/FbPlace.cs new file mode 100644 index 00000000..20edab2c --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/FbPlace.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class FbPlace + { + [JsonProperty("location")] + public FbLocation Location { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + + [JsonProperty("media_bundles")] + public IList MediaBundles { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/FbSearchPlaceResponse.cs b/InstaSharper/Classes/ResponseWrappers/FbSearchPlaceResponse.cs new file mode 100644 index 00000000..12e69cd9 --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/FbSearchPlaceResponse.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class FbSearchPlaceResponse + { + [JsonProperty("items")] public IList Items { get; set; } + + [JsonProperty("has_more")] public bool HasMore { get; set; } + + [JsonProperty("rank_token")] public string RankToken { get; set; } + + [JsonProperty("status")] public string Status { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/InstaChallenge.cs b/InstaSharper/Classes/ResponseWrappers/InstaChallenge.cs new file mode 100644 index 00000000..f43b0d4d --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/InstaChallenge.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class InstaChallenge + { + [JsonProperty("url")] public string Url { get; set; } + + [JsonProperty("api_path")] public string ApiPath { get; set; } + + [JsonProperty("hide_webview_header")] public bool HideWebviewHeader { get; set; } + + [JsonProperty("lock")] public bool Lock { get; set; } + + [JsonProperty("logout")] public bool Logout { get; set; } + + [JsonProperty("native_flow")] public bool NativeFlow { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/InstaNametag.cs b/InstaSharper/Classes/ResponseWrappers/InstaNametag.cs new file mode 100644 index 00000000..17f4c0bb --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/InstaNametag.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class InstaNametag + { + + [JsonProperty("mode")] + public int Mode { get; set; } + + [JsonProperty("gradient")] + public int Gradient { get; set; } + + [JsonProperty("emoji")] + public string Emoji { get; set; } + + [JsonProperty("selfie_sticker")] + public int SelfieSticker { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/InstaResetChallenge.cs b/InstaSharper/Classes/ResponseWrappers/InstaResetChallenge.cs new file mode 100644 index 00000000..63acf09c --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/InstaResetChallenge.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class InstaResetChallenge + { + [JsonProperty("step_name")] public string StepName { get; set; } + + [JsonProperty("step_data")] public InstaStepData StepData { get; set; } + + [JsonProperty("user_id")] public long UserId { get; set; } + + [JsonProperty("nonce_code")] public string NonceCode { get; set; } + + [JsonProperty("status")] public string Status { get; set; } + + [JsonProperty("logged_in_user")] public InstaUserResponse LoggedInUser { get; set; } + + [JsonProperty("action")] public string Action { get; set; } + + [JsonProperty("auto_login")] public bool AutoLogin { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/InstaStepData.cs b/InstaSharper/Classes/ResponseWrappers/InstaStepData.cs new file mode 100644 index 00000000..79cb8aa4 --- /dev/null +++ b/InstaSharper/Classes/ResponseWrappers/InstaStepData.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace InstaSharper.Classes.ResponseWrappers +{ + public class InstaStepData + { + [JsonProperty("choice")] public string Choice { get; set; } + + [JsonProperty("fb_access_token")] public string FbAccessToken { get; set; } + + [JsonProperty("big_blue_token")] public string BigBlueToken { get; set; } + + [JsonProperty("google_oauth_token")] public string GoogleOauthToken { get; set; } + + [JsonProperty("email")] public string Email { get; set; } + + [JsonProperty("phone_number")] public string PhoneNumber { get; set; } + } +} \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/InstaUserResponse.cs b/InstaSharper/Classes/ResponseWrappers/InstaUserResponse.cs index 63e3357a..3293662b 100644 --- a/InstaSharper/Classes/ResponseWrappers/InstaUserResponse.cs +++ b/InstaSharper/Classes/ResponseWrappers/InstaUserResponse.cs @@ -6,8 +6,7 @@ public class InstaUserResponse : InstaUserShortResponse { [JsonProperty("friendship_status")] public InstaFriendshipStatusResponse FriendshipStatus { get; set; } - [JsonProperty("has_anonymous_profile_picture")] - public bool HasAnonymousProfilePicture { get; set; } + [JsonProperty("has_anonymous_profile_picture")] public bool HasAnonymousProfilePicture { get; set; } [JsonProperty("follower_count")] public int FollowersCount { get; set; } @@ -15,12 +14,34 @@ public class InstaUserResponse : InstaUserShortResponse [JsonProperty("social_context")] public string SocialContext { get; set; } - [JsonProperty("search_social_context")] - public string SearchSocialContext { get; set; } + [JsonProperty("search_social_context")] public string SearchSocialContext { get; set; } - [JsonProperty("mutual_followers_count")] - public string MulualFollowersCount { get; set; } + [JsonProperty("mutual_followers_count")] public string MulualFollowersCount { get; set; } [JsonProperty("unseen_count")] public int UnseenCount { get; set; } + + [JsonProperty("can_boost_post")] public bool CanBoostPost { get; set; } + + [JsonProperty("show_insights_terms")] public bool ShowInsightsTerms { get; set; } + + [JsonProperty("is_business")] public bool IsBusiness { get; set; } + + [JsonProperty("nametag")] public InstaNametag Nametag { get; set; } + + [JsonProperty("has_placed_orders")] public bool HasPlacedOrders { get; set; } + + [JsonProperty("can_see_organic_insights")] public bool CanSeeOrganicInsights { get; set; } + + [JsonProperty("allowed_commenter_type")] public string AllowedCommEnterType { get; set; } + + [JsonProperty("reel_auto_archive")] public string ReelAutoArchive { get; set; } + + [JsonProperty("allow_contacts_sync")] public bool AllowContactsSync { get; set; } + + [JsonProperty("phone_number")] public string PhoneNumber { get; set; } + + [JsonProperty("country_code")] public int CountryCode { get; set; } + + [JsonProperty("national_number")] public long NationalNumber { get; set; } } } \ No newline at end of file diff --git a/InstaSharper/Classes/Result.cs b/InstaSharper/Classes/Result.cs index 040b455d..31d89c95 100644 --- a/InstaSharper/Classes/Result.cs +++ b/InstaSharper/Classes/Result.cs @@ -98,6 +98,9 @@ public static IResult UnExpectedResponse(HttpResponseMessage response, str case "sentry_block": responseType = ResponseType.SentryBlock; break; + case "checkpoint_challenge_required": + responseType = ResponseType.CheckPointChallengeRequired; + break; } if (!status.IsOk() && status.Message.Contains("wait a few minutes")) diff --git a/InstaSharper/Helpers/UriCreator.cs b/InstaSharper/Helpers/UriCreator.cs index d1168a60..91bd6a28 100644 --- a/InstaSharper/Helpers/UriCreator.cs +++ b/InstaSharper/Helpers/UriCreator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using InstaSharper.API; using InstaSharper.Classes.Models; @@ -75,7 +76,7 @@ public static Uri GetUserMediaListUri(long userPk, string nextId = "") return !string.IsNullOrEmpty(nextId) ? new UriBuilder(instaUri) {Query = $"max_id={nextId}"}.Uri : instaUri; - } + } public static Uri GetCreateAccountUri() { if (!Uri.TryCreate(BaseInstagramUri, InstaApiConstants.ACCOUNTS_CREATE, out var instaUri)) @@ -88,6 +89,27 @@ public static Uri GetLoginUri() throw new Exception("Cant create URI for user login"); return instaUri; } + + public static Uri GetResetChallengeUri(string token) + { + if (!Uri.TryCreate(BaseInstagramUri, string.Format(InstaApiConstants.RESET_CHALLENGE, token), out var instaUri)) + throw new Exception("Cant create URI for challenge reset"); + return instaUri; + } + + public static Uri GetVerifyMethod(string token) + { + if (!Uri.TryCreate(BaseInstagramUri, string.Format(InstaApiConstants.VERIFY_METHOD, token), out var instaUri)) + throw new Exception("Cant create URI for challenge verify method"); + return instaUri; + } + + public static Uri GetFbSearchPlace(int count, string rankToken, string searchQuery) + { + if (!Uri.TryCreate(BaseInstagramUri, string.Format(InstaApiConstants.FB_SEARCH_PLACE, count, searchQuery, rankToken), out var instaUri)) + throw new Exception("Cant create URI for fb search place"); + return instaUri; + } public static Uri GetTwoFactorLoginUri() { @@ -338,7 +360,7 @@ public static Uri GetDeleteCommetUri(string mediaId, string commentId) out var instaUri)) throw new Exception("Cant create URI for delete comment"); return instaUri; - } + } public static Uri GetUploadVideoUri() { if ( From 0905b7bf70dcaee70a7317aa88db756e5da61f8c Mon Sep 17 00:00:00 2001 From: Arzhang Mosaffa Date: Sat, 6 Oct 2018 08:37:02 +0330 Subject: [PATCH 2/3] set LoggedInUser & RankToken after solving challenge we're actually signed in after solving challenge relogin causes new challenge --- InstaSharper/API/InstaApi.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/InstaSharper/API/InstaApi.cs b/InstaSharper/API/InstaApi.cs index 560aa8f8..71b1dd47 100644 --- a/InstaSharper/API/InstaApi.cs +++ b/InstaSharper/API/InstaApi.cs @@ -1163,6 +1163,9 @@ public async Task> SendVerifyCode(string securityCo } var sendVerifyCodeResponse = JsonConvert.DeserializeObject(json); IsUserAuthenticated = sendVerifyCodeResponse.LoggedInUser?.UserName.ToLower() == _user.UserName.ToLower(); + var converter = ConvertersFabric.Instance.GetUserShortConverter(sendVerifyCodeResponse.LoggedInUser); + _user.LoggedInUder = converter.Convert(); + _user.RankToken = $"{_user.LoggedInUder.Pk}_{_httpRequestProcessor.RequestMessage.phone_id}"; return Result.Success(sendVerifyCodeResponse); } From 798a13a12649e2bfa3d9283d781d46d5abdd89a0 Mon Sep 17 00:00:00 2001 From: Arzhang Mosaffa Date: Sat, 6 Oct 2018 08:42:52 +0330 Subject: [PATCH 3/3] I've added some undiscovered ResponseTypes Spam ActionBlocked DeletedPost TemporarilyBlocked CantLikeMedia InvalidChallengeCode --- InstaSharper/Classes/ResponseType.cs | 8 ++++- .../ResponseWrappers/BadStatusResponse.cs | 15 ++++++-- InstaSharper/Classes/Result.cs | 34 +++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/InstaSharper/Classes/ResponseType.cs b/InstaSharper/Classes/ResponseType.cs index a6e3980d..7b5cde5c 100644 --- a/InstaSharper/Classes/ResponseType.cs +++ b/InstaSharper/Classes/ResponseType.cs @@ -12,6 +12,12 @@ public enum ResponseType SomePagesSkipped = 7, UnExpectedResponse = 8, InternalException = 9, - CheckPointChallengeRequired = 10 + CheckPointChallengeRequired = 10, + Spam = 11, + ActionBlocked = 12, + DeletedPost = 13, + TemporarilyBlocked = 14, + CantLikeMedia = 15, + InvalidChallengeCode = 16, } } \ No newline at end of file diff --git a/InstaSharper/Classes/ResponseWrappers/BadStatusResponse.cs b/InstaSharper/Classes/ResponseWrappers/BadStatusResponse.cs index c08404ed..d31e659b 100644 --- a/InstaSharper/Classes/ResponseWrappers/BadStatusResponse.cs +++ b/InstaSharper/Classes/ResponseWrappers/BadStatusResponse.cs @@ -7,9 +7,20 @@ public class BadStatusResponse : BaseStatusResponse { [JsonProperty("message")] public string Message { get; set; } - [JsonProperty("error_type")] - public string ErrorType { get; set; } = "unknown"; + [JsonProperty("error_type")] public string ErrorType { get; set; } = "unknown"; [JsonProperty("checkpoint_url")] public string CheckPointUrl { get; set; } + + [JsonProperty("spam")] public bool Spam { get; set; } + + [JsonProperty("feedback_title")] public string FeedbackTitle { get; set; } + + [JsonProperty("feedback_message")] public string FeedbackMessage { get; set; } + + [JsonProperty("feedback_appeal_label")] public string FeedbackAppealLabel { get; set; } + + [JsonProperty("feedback_action")] public string FeedbackAction { get; set; } + + [JsonProperty("feedback_ignore_label")] public string FeedbackIgnoreLabel { get; set; } } } \ No newline at end of file diff --git a/InstaSharper/Classes/Result.cs b/InstaSharper/Classes/Result.cs index 46056b66..a9aa7167 100644 --- a/InstaSharper/Classes/Result.cs +++ b/InstaSharper/Classes/Result.cs @@ -105,6 +105,40 @@ public static IResult UnExpectedResponse(HttpResponseMessage response, str break; } + if (status.Spam) responseType = ResponseType.Spam; + switch (status.FeedbackTitle) + { + // feedback_message: This action was blocked. Please try again later. + // We restrict certain content and actions to protect our community. + // Tell us if you think we made a mistake. + case "Action Blocked": + responseType = ResponseType.ActionBlocked; + break; + // feedback_message: It looks like you were misusing this feature by going too fast. + // You’ve been temporarily blocked from using it. We restrict certain content and actions + // to protect our community. Tell us if you think we made a mistake. + case "You’re Temporarily Blocked": + responseType = ResponseType.TemporarilyBlocked; + break; + } + + switch (status.FeedbackMessage) + { + case "The post you were viewing has been deleted.": + responseType = ResponseType.DeletedPost; + break; + } + + switch (status.Message) + { + case "Sorry, you cannot like this media": + responseType = ResponseType.CantLikeMedia; + break; + case "Please check the code we sent you and try again.": + responseType = ResponseType.InvalidChallengeCode; + break; + } + if (!status.IsOk() && status.Message.Contains("wait a few minutes")) responseType = ResponseType.RequestsLimit;