1

I have a url:

https://www.facebook.com/dialog/oauth?client_id=559149457475028&redirect_uri=https://calm-refuge-2106.herokuapp.com/&scope=publish_stream

It redirects to another page with url:

https://calm-refuge-2106.herokuapp.com/?code=AQAoBPyS4lKynHM4lylFHChFyO775T-49A1j8DbTGO9iiyoKnkDv0naSWMSvJ26ISt50fTUGcYH8QfUdLwt4sLBQ9noNmBCuUsze4rVSjxCcJ1pbfcLpfy2OyLB5DMg7sOWr_q5dEHNEd9eXoeRepmjFDU7GyEUx6WrjDtIOcusH4prnPGhQ2gHopJC54AeflMC9bh6fP2R6OhAJhVCVMHNvIT2wwTB8DG46yoRP1GAqN-d2vm8RwOC93vY-Xv_HvGQKwhRxbpVlk2vWTMQ40F1rbaw_zJNz7oBtz7qDUQkxI3RcE6dWw5GEzPcFMFuD1jw#_=_

where I need to take only code query.

When I use urllib.urlopen to open the url and then geturl method to returned file-like object it returns something like this: https://www.facebook.com/login.php?skip_api_login=1&api_key=559149457475028&signed_next=1&next=https%3A%2F%2Fwww.facebook.com%2Fdialog%2Foauth%3Fredirect_uri%3Dhttps%253A%252F%252Fcalm-refuge-2106.herokuapp.com%252F%26scope%3Dpublish_stream%26client_id%3D559149457475028%26ret%3Dlogin&cancel_uri=https%3A%2F%2Fcalm-refuge-2106.herokuapp.com%2F%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&display=page

It's clearly not what i was looking for.

How can I get a url after redirecting in Python?

Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59
  • `https://www.facebook.com/login.php` I'd say it's the url of Facebook login page. Your `GET` request is not authentified. – Thierry J. Aug 26 '13 at 03:08
  • What do you mean? I'm logged in on Facebook. – Sergey Ivanov Aug 26 '13 at 03:31
  • 1
    Yes, you are logged in Facebook in your browser, but your python application does not use the authentication information stored in your browser. You need to login to Facebook in your python application, save the cookie information about the login and use this to access the webpage afterwards. – Thierry J. Aug 26 '13 at 03:51
  • I tried to use pyfb library which makes this work under the hood. But the problem that I need to pass access token manually. How can I authenticate python in this app concretely? – Sergey Ivanov Aug 26 '13 at 04:02

1 Answers1

1

try urllib2.HTTPRedirectHandler

Ihab Shoully
  • 2,311
  • 1
  • 20
  • 22
  • This post also refers to HTTPRedirectHandler: http://stackoverflow.com/questions/4902523/how-to-get-the-url-of-a-redirect-with-python – GDICommander Aug 26 '13 at 01:09
  • urllib2 didn't help. Every time it gives the same url. I don't understand how to use HTTPRedirectHandler in this case. – Sergey Ivanov Aug 26 '13 at 01:36