ramtinak / InstagramApiSharp

A complete Private Instagram API for .NET (C#, VB.NET).
MIT License
792 stars 239 forks source link

Challenge while you already logged in #204

Closed ramtinak closed 5 years ago

ramtinak commented 5 years ago

Issue category

Language

Usage

Debug logs

1.
Request: POST /api/v1/feed/timeline/
....
Response: 
{
    "message": "challenge_required",
    "challenge": {
        "url": "https://i.instagram.com/challenge/",
        "api_path": "/challenge/",
        "hide_webview_header": true,
        "lock": true,
        "logout": false,
        "native_flow": true
    },
    "status": "fail"
}

2.
Request: GET /api/v1/challenge/?guid=6324ecb2-e663-4dc8-a3a1-289c699cc876&device_id=android-21c311d494a974fe
Response:
{
    "step_name": "delta_login_review",
    "step_data": {
        "choice": "1",
        "country": "United States",
        "enrollment_time": 1551926629,
        "enrollment_date": "Mar 06, 06:43PM",
        "latitude": 33.6127,
        "longitude": -117.656,
        "city": "Mission Viejo, California",
        "platform": "Web",
        "user_agent": "Chrome Mobile WebView on Android 8.0 in PRA-LA1"
    },
    "status": "ok"
}

3.
It will FIX it:
Request: /api/v1/challenge/
Req data: signed_body=0b0948ce41143512ec32fc4cb2282e7e0076b497eb6d473b361a1209371604ee.{"choice":"0","_csrftoken":"TOKEN","_uid":"PK","guid":"6324ecb2-e663-4dc8-a3a1-289c699cc876","device_id":"android-21c311d494a974fe","_uuid":"6324ecb2-e663-4dc8-a3a1-289c699cc876"}&ig_sig_key_version=4

Response:
{"action": "close", "status": "ok"}

Describe your issue

This will be a fix for Challenge while you already logged in .

Screenshot

image

ramtinak commented 5 years ago

Added https://github.com/ramtinak/InstagramApiSharp/commit/f4f3cf69bc02cdc6a7ed3f581aef1521c95b18c7

Intro: https://github.com/ramtinak/InstagramApiSharp/blob/42a5f6cdbb8d82838ca29c94ca5a544122b9232a/samples/ChallengeRequireExample/Form1.cs#L41-L50

Example: https://github.com/ramtinak/InstagramApiSharp/blob/42a5f6cdbb8d82838ca29c94ca5a544122b9232a/samples/ChallengeRequireExample/Form1.cs#L377-L390

DenisKrsk commented 5 years ago

I had the same problem. Comparing the application traffic I came to the conclusion that it depends on the parameter "device_id":"android-8907s3f76g3s4641". If you put a value from a real device, this error does not occur.

ghost commented 5 years ago

@ramtinak Can you please add this changes also in nuget library?

DenisKrsk commented 5 years ago

Also helps to change the ip

ramtinak commented 5 years ago

@DenisKrsk I think you are wrong! This challenge is this one: image

This is happened while you are trying to login with another device and IP address and this challenge will pop up to your logged account in other device.

It doesn't related to LoginAsync at all!. Also using a real device id it's on you, you can use actual device id for your own login using custom device. We can't set real device id because so many people using InstagramApiSharp so we just create a new GUID for each login.

@sopranidaniele I will update it tonight.

ghost commented 5 years ago

I found an issue in the AcceptChallengeAsync() function. It throws this Exception: user must be authenticated at InstagramApiSharp.Helpers.UserAuthValidator.Validate(UserAuthValidate userAuthValidate) at InstagramApiSharp.API.InstaApi.AcceptChallengeAsync()

that's the code:

var res = await Api.VerifyCodeForChallengeRequireAsync(code);                               

switch (res.Value)
{
     case InstaLoginResult.ChallengeRequired:                                  
     var result = await Api.AcceptChallengeAsync(); //Exception
     break;
}

This Exception is thrown only sometimes by some users.

ramtinak commented 5 years ago

@sopranidaniele This isn't a bug related to AcceptChallengeAsync ! You CANNOT use AcceptChallengeAsync for login challenge! This is for users that already logged in and passed default challenge(if any) and IsUserAuthenticated are TRUE (successfully logins).

As you can see here, I didn't put the accepting challenge code for VerifyCodeForChallengeRequireAsync(code); or any other challenge function! https://github.com/ramtinak/InstagramApiSharp/blob/42a5f6cdbb8d82838ca29c94ca5a544122b9232a/samples/ChallengeRequireExample/Form1.cs#L377-L390

This is for all other functions (get thread, send message, follower/followings list, follow/unfollow, like/unlike, uploading video/image/album, get story and etc.) if you across to Challenge while you requesting for these functions, you just simply accept it without doing new re-login!

Please read this comments in ChallengeExample project: https://github.com/ramtinak/InstagramApiSharp/blob/85a4bb3e5911bf27d5aa5ad87d0e5bbd9aae60f6/samples/ChallengeRequireExample/Form1.cs#L41-L83

ghost commented 5 years ago

ops I'm sorry, but what I have to do if the response for VerifyCodeForChallengeRequireAsync(code) is InstaLoginResult.ChallengeRequired?

ramtinak commented 5 years ago

@sopranidaniele Please check https://github.com/ramtinak/InstagramApiSharp/blob/master/samples/ChallengeRequireExample/Form1.cs and read comments.

ghost commented 5 years ago

I read all the comments, i understood how to use AcceptChallenge function, but when I send the verification code to solve the challenge (VerifyCodeForChallengeRequireAsync), the response type is InstaLoginResult.ChallengeRequired. I only want to know how to handle this event.

In your Example there is not explained how to handle that event, you only show to handle it when the response is InstaLoginResult.TwoFactorRequired.