subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.21k stars 667 forks source link

[BUG] user_following not working #1050

Open Laura-Ag opened 1 year ago

Laura-Ag commented 1 year ago

Hello, i get this error instagrapi.exceptions.LoginRequired: login_required Any ideas please?

Laura-Ag commented 1 year ago

Hello,

here is my code:

from instagrapi import Client

API = Client()

USERNAME = 'username'
PASSWORD = 'password'

def init_user():
    try:
        print('Logging in...')
        API.login(USERNAME, PASSWORD)
        print('Logged in successfully!\n')

        print('Getting user info...')
        user_id = API.user_id_from_username(USERNAME)
        print('User ID:', user_id)

        user_followings = API.user_following(user_id, 0)

        print('Done!\n')

        return user_followings

    except Exception as error:
        print('\nSomething went wrong:', error)
        print('\nExiting script...\n')
        sys.exit()

Terminal Output:

Logged in successfully!

Getting user info...
User ID: XXXXXXXXX

Something went wrong: login_required
adw0rd commented 1 year ago

@Laura-Ag try using user_following_v1 instead of user_following

Laura-Ag commented 1 year ago

Hello @adw0rd and thank you for your answer. I used user_following_v1 but it didn't work either.

jarrodnorwell commented 1 year ago

@Laura-Ag Can you print the return from API.login(...)? Could be that it's not actually logged in.

might not throw an error but still be unsuccessful

Do you have email or any other 2FA enabled on the account?

Laura-Ag commented 1 year ago

Hello @official-antique and thank you for your time! It prints True.

Laura-Ag commented 1 year ago

Hello @insolitum! Yes I am using the latest version.

Here is the traceback


  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\instagrapi\mixins\private.py", line 302, in _send_private_request
    response.raise_for_status()
  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\requests\models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://i.instagram.com/api/v1/friendships/xxxxxxxxxx/following/?rank_token=xxxxxxxxxx_5cceb876-8ab2-4332-9ee9-2d0d54604e95&search_surface=follow_list_page&includes_hashtags=true&enable_groups=true&query=&count=10000&max_id=4000

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\....\instaspector.py", line 89, in <module>
    user_followings = init_user()
  File "c:\Users\....\InstaSpector\instaspector.py", line 27, in init_user
    user_followings = API.user_following_v1(user_id, 0)
  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\instagrapi\mixins\user.py", line 552, in user_following_v1
    result = self.private_request(f"friendships/{user_id}/following/", params=params)
  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\instagrapi\mixins\private.py", line 451, in private_request
    raise e
  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\instagrapi\mixins\private.py", line 438, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "C:\Users\....\Programs\Python\Python39-32\lib\site-packages\instagrapi\mixins\private.py", line 327, in _send_private_request
    raise LoginRequired(response=e.response, **last_json)
instagrapi.exceptions.LoginRequired: login_required
Laura-Ag commented 1 year ago

Hello, any ideas guys?

bueroingleuering commented 1 year ago

I have the same problem. user_followersworks, but user_followingis not working, since I got an exception: instagrapi.exceptions.LoginRequired: login_required

code: cl = Client() cl.login(username="Insta_account", password="insta_password") follower = cl.user_followers(user_id=cl.user_id) following = cl.user_following(user_id=cl.user_id)

Trace: requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://i.instagram.com/api/v1/friendships/xxxxxxx/following/?max_id=&count=10000&rank_token=xxxxxxx_51a0f7a3-1955-40b8-985e-86af526efdf5&search_surface=follow_list_page&query=&enable_groups=true

Laura-Ag commented 1 year ago

Hello, I still have the same problem.

adw0rd commented 1 year ago

@Laura-Ag @bueroingleuering try cl.user_following_gql or https://api.lamadava.com/docs

isakurbanov744 commented 1 year ago

I also have the same issue, the request stays for some time and then it gives error.

isakurbanov744 commented 1 year ago

Please provide with updates for solutions.

Laura-Ag commented 1 year ago

Neither cl.user_following_gql works.

Laura-Ag commented 1 year ago

Any other ideas, please?

adw0rd commented 1 year ago

cl.user_following_v1?

isakurbanov744 commented 1 year ago

Doesn't work for me, even if it works, I can't retrieve all of the followings.

claell commented 1 year ago

Probably unrelated, but I have problems as well: instagrapi.exceptions.ClientBadRequestError: Unknown ({'message': '', 'response': <Response [400]>, 'status': 'fail'})

Possibly due to many requests? I'll try the _v1 function.

claell commented 1 year ago

Hm, _v1 gives me the same error.

Before, I execute user_followers, which works fine. If I put the user_following function before that, I still get the same error. The numbers for the account are currently 96 followers vs. 137 following. So not sure whether this can already be too much and cause some limit error?

Laura-Ag commented 1 year ago

Hello,

still not fixed. Any ideas?

LFZDavid commented 8 months ago

Hello, I have try with user_following_gql and it works for me. Hope it will for you