instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

[BUG] user_following not working

Open Laura-Ag opened this issue 2 years ago • 21 comments

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

Laura-Ag avatar Jan 03 '23 20:01 Laura-Ag

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

Laura-Ag avatar Jan 08 '23 19:01 Laura-Ag

@Laura-Ag try using user_following_v1 instead of user_following

adw0rd avatar Jan 09 '23 07:01 adw0rd

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

Laura-Ag avatar Jan 09 '23 17:01 Laura-Ag

@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?

jarrodnorwell avatar Jan 09 '23 17:01 jarrodnorwell

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

Laura-Ag avatar Jan 09 '23 17:01 Laura-Ag

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 avatar Jan 09 '23 18:01 Laura-Ag

Hello, any ideas guys?

Laura-Ag avatar Jan 24 '23 19:01 Laura-Ag

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

bueroingleuering avatar Apr 02 '23 20:04 bueroingleuering

Hello, I still have the same problem.

Laura-Ag avatar Apr 10 '23 16:04 Laura-Ag

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

adw0rd avatar Apr 10 '23 16:04 adw0rd

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

isakurbanov744 avatar Apr 11 '23 14:04 isakurbanov744

Please provide with updates for solutions.

isakurbanov744 avatar Apr 11 '23 14:04 isakurbanov744

Neither cl.user_following_gql works.

Laura-Ag avatar Apr 12 '23 13:04 Laura-Ag

Any other ideas, please?

Laura-Ag avatar Apr 19 '23 18:04 Laura-Ag

cl.user_following_v1?

adw0rd avatar Apr 19 '23 21:04 adw0rd

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

isakurbanov744 avatar Apr 20 '23 07:04 isakurbanov744

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 avatar Apr 21 '23 10:04 claell

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?

claell avatar Apr 21 '23 10:04 claell

Hello,

still not fixed. Any ideas?

Laura-Ag avatar May 18 '23 15:05 Laura-Ag

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

LFZDavid avatar Jan 07 '24 16:01 LFZDavid