kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.42k stars 628 forks source link

Login unsuccessful #28

Open yushaamalik opened 4 years ago

yushaamalik commented 4 years ago

for post in get_posts(group='EatsleeprepeatESR/', credentials={'email' : 'yushaa.malik6969@gmail.com' , 'pass' : '*****'}): print(post['text'][:50])

This is my code. Despite of providing my correct credentials, it gives me error: " warnings.warn('login unsuccessful') UserWarning: login unsuccessful"

lazanet commented 4 years ago

credentials should be tupple

for post in get_posts(group='EatsleeprepeatESR/', credentials=('yushaa.malik6969@gmail.com', '*****************')):
    print(post['text'][:50])

Also check if you have 2 factor auth enabled (I guess that would also produce login unsuccessful)

yushaamalik commented 4 years ago

Empty console. Nothing happens. No error, nothing. Also, I do not have 2 factor auth enabled.

kevinzg commented 4 years ago

A way to check if the login is successful is to request some path that requires authentication, e.g.:

next(facebook_scraper.get_posts(account='something', credentials=('email@user.com', '***'))
response = facebook_scraper._session.get('https://m.facebook.com/settings', allow_redirects=False)
print(response.status_code)

If it prints 200 it means the login worked, 300 means it didn't.

You might want to check the response from the post request in the login function to see what went wrong:

https://github.com/kevinzg/facebook-scraper/blob/0636e1636379f164b2ed808257c4f0e94a4add34/facebook_scraper.py#L271-L274

Also, I've noticed group scraping doesn't work sometimes :confused:, so maybe the issue is not login related.

yushaamalik commented 4 years ago

The login works, yet there is not data scraped.

ranaalisaeed commented 4 years ago

Same problem, no data scraped.

demangejeremy commented 4 years ago

Same problem too, no data scraped. @kevinzg

barakplasma commented 4 years ago

I also had this issue.

I tried logging in before and after disabling multi-factor authentication using a generated App Password.

Something I noticed while creating my PR above is that the latest (not yet released) version of the login function will probably include more debugging info for login difficulties. https://github.com/kevinzg/facebook-scraper/blob/1a703c8cc4576ac2a85ecf65200078e19362925c/facebook_scraper/facebook_scraper.py#L71-L78

So hopefully we will be able to view the debug info for the login attempts using an argument/option in the next release

ntampouratzis commented 3 years ago

I have installed the latest version (10 Nov 2020) of facebook_scraper. I execute the code:

import facebook_scraper
get_p = facebook_scraper.get_posts('nitento', credentials=('bilospap.2020@gmail.com', '***'))

and i get the following:

C:\Users\tampn\Anaconda3\lib\site-packages\facebook_scraper\facebook_scraper.py:80: UserWarning: login unsuccessful warnings.warn('login unsuccessful')

To be noticed that, I have disabled multi-factor authentication!

Can you help me, please? Best regards

Alex-AMC commented 3 years ago

Same here

joakimremler commented 3 years ago

same here

jaxnz commented 3 years ago

I can confirm the issue is with Groups. I can scrape pages, I change to a group and get a login unsuccessful message

Ting0887 commented 3 years ago

same here

Nammontara commented 3 years ago

Same here bro, Is someone has any solution?

smitha001 commented 3 years ago

same. i am a total python newbie. this is an amazing resource. I am standing on the shoulders of giants. but login unsuccessful. waaaah.

kevinzg commented 3 years ago

I added a cookies parameter on the latest version, try with that please.

To use it log into Facebook on your browser, then install an extension to export the cookie file, like this one. Then do get_posts('page', cookies='path/to/cookies.txt'). The file format should be the Netscape one. You can also pass a CookieJar or a dictionary that will be converted to a cookie jar using cookiejar_from_dict instead.

Please report back as I haven't tried it.

neon-ninja commented 3 years ago

I tried https://github.com/kevinzg/facebook-scraper/commit/b4812f859c36ef0206a6a9c9921d60c2f2aa4026, it just needed one minor change to get it working - https://github.com/kevinzg/facebook-scraper/pull/175

kaito-th commented 3 years ago

I got "Login Approval Needed" on CLI.

Please tell me what I should do?

neon-ninja commented 3 years ago

You need to login with a browser and approve the login

kaito-th commented 3 years ago

Thank for replying

I've done 2FA but still didn't work

kaito-th commented 3 years ago

I logged in with a browser then ran the code, in the first loop, unauthorized devices notification popped up and I approved it then the next loop same issue occur as if it's not the same device/ user agent.

neon-ninja commented 3 years ago

Maybe just use cookies then

kaito-th commented 3 years ago

get_posts(target_id, pages=5, extra_info=True, credentials=(_email, _password), cookies='cookies.json')

I got '_email' is not defined. Do I have to set credentials when I use cookies? What should I do with this argument?

neon-ninja commented 3 years ago

no, use one or the other. Just delete the credentials argument if you don't need it

Natengaki commented 2 years ago

Hello, I'm having trouble using the lib. I want to scrape the pages and information from different profiles. It needs to be logged while for others not, I guess it's due to the security of FB i tried several things, but nothing works : for post in get_posts(group='EatsleeprepeatESR/', credentials={'email' : 't@hotmail.fr' , 'pass' : "pass"}): print(post['text'][:50]) OR for post in get_posts(group='EatsleeprepeatESR/', credentials=('@hotmail.fr' ,"password")): print(post['text'][:50]) But it gives the following error: facebook_scraper.exceptions.LoginError: Login unsuccessful

I tried this : print(get_profile("pageName",cookies='Path/cookies.txt')) print(get_post("pageName",cookies='Path/cookies.txt'))

I put both user_c and xs cookies in cookies.txt but it doesn't work. No error in the terminal

To finish : I tried this next(facebook_scraper.get_posts(account = 'pageName' , credentials = ("@hotmail.fr" , "password")) response=facebook_scraper._session.get('https://m.facebook.com/settings',allow_redirects=False) print(response.status_code) but I have this error : response=facebook_scraper._session.get('https://m.facebook.com/settings',allow_redirects=False) ^ SyntaxError: invalid syntax

Could you help me ? I work under kali linux and I am in Europe

neon-ninja commented 2 years ago

try update to latest master, a recent PR (https://github.com/kevinzg/facebook-scraper/pull/606) fixed an issue with logins originating from Europe

Natengaki commented 2 years ago

essayez de mettre à jour le dernier maître, un récent PR ( #606 ) a corrigé un problème avec les connexions provenant d'Europe

Thank it work for profiles.