Python Requests Facebook Login !!HOT!!
To add to what has been said in the previous example, we can implement the following try/except block to catch any of the 4XX and 5XX errors that requests may throw when it receives the above error status codes. The default behavior is to raise an error by returning a requests.exceptions.HTTPError object that contains the reason in the status_code field. We used a try block to catch all of the errors we were expecting and the except block to handle all the exceptions for which we have registered a custom exception handler. When we log the response that we get after a login attempt with the Facebook SDK, we can see that it indeed returns an HTTP-based error. However, if we log the response that we get after a non-Facebook login, we can see that it only returns a 4XX or 5XX response code.
python requests facebook login
The third login method that we will look at is the Twitter login. The REST API specification for the followers and friends methods requires the screen_name field to be provided in the Authorization HTTP header. For requests that require an OAuth token, the token will be provided in the Authorization header too.