Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login unsuccessful #28

Open
yushaamalik opened this issue Jan 1, 2020 · 26 comments
Open

Login unsuccessful #28

yushaamalik opened this issue Jan 1, 2020 · 26 comments

Comments

@yushaamalik
Copy link

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
Copy link
Contributor

lazanet commented Jan 7, 2020

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
Copy link
Author

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

@kevinzg
Copy link
Owner

kevinzg commented Jan 21, 2020

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:

def _login_user(email, password):
login_page = _session.get(_base_url)
login_action = login_page.html.find('#login_form', first=True).attrs.get('action')
_session.post(_base_url + login_action, data={'email': email, 'pass': password})

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

@yushaamalik
Copy link
Author

The login works, yet there is not data scraped.

@ranaalisaeed
Copy link

Same problem, no data scraped.

@demangejeremy
Copy link

demangejeremy commented Jun 8, 2020

Same problem too, no data scraped. @kevinzg

@barakplasma
Copy link
Contributor

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.

logger.debug("Login response text: %s", response_text)
login_error = response.html.find('#login_error', first=True)
if login_error:
logger.error("Login error: %s", login_error.text)
if 'c_user' not in self.session.cookies:
warnings.warn('login unsuccessful')

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

@ntampouratzis
Copy link

ntampouratzis commented Nov 14, 2020

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
Copy link

Same here

@joakimremler
Copy link

same here

@jaxnz
Copy link

jaxnz commented Jan 8, 2021

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

@Ting0887
Copy link

same here

@Nammontara
Copy link

Same here bro, Is someone has any solution?

@smitha001
Copy link

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
Copy link
Owner

kevinzg commented Mar 8, 2021

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
Copy link
Collaborator

I tried b4812f8, it just needed one minor change to get it working - #175

@kaito-th
Copy link

kaito-th commented Sep 4, 2021

I got "Login Approval Needed" on CLI.

Please tell me what I should do?

@neon-ninja
Copy link
Collaborator

You need to login with a browser and approve the login

@kaito-th
Copy link

kaito-th commented Sep 4, 2021

Thank for replying

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

@kaito-th
Copy link

kaito-th commented Sep 4, 2021

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
Copy link
Collaborator

Maybe just use cookies then

@kaito-th
Copy link

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
Copy link
Collaborator

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

@Natengaki
Copy link

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
Copy link
Collaborator

try update to latest master, a recent PR (#606) fixed an issue with logins originating from Europe

@Natengaki
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests