0

I'm trying load facebook content with CURL, but the system is showing the login page instead of my timeline (also, I'm already signed in). Is something related to cookies? What I'm doing wrong? There's no errors in this code...

 $ch = curl_init('https://www.facebook.com');
 curl_setopt($ch, CURLOPT_POST, true );
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
 $header = array();
 $header[] = "Accept-Language: pt-br,pt;q=0.5"; 
 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
 curl_setopt($ch, CURLOPT_HEADER, false );
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
 curl_setopt($ch, CURLOPT_VERBOSE,true);
 $data = curl_exec( $ch );
 echo $data;

I hope you help me! Thank you

Erika
  • 1
  • 1
    Your browser is logged in, but the server you're running this script on isn't. See the post here: https://stackoverflow.com/questions/23186168/php-curl-to-login-to-facebook – FoulFoot Aug 25 '18 at 22:38
  • You're talking about two different universes here, @Erika. When you login through your web-browser this information is only visible for you. The same as when you try to access again from another browser in the same computer. So if you try from the server, it will require another authentication. Also, Facebook forbids scraping their information, as you can read here: https://www.facebook.com/apps/site_scraping_tos_terms.php – Rafael Aug 25 '18 at 22:39
  • @Rafael check term 2 `You will not engage in Automated Data Collection without Facebook's express written permission.`. So if you ask nicely and give the reasons why, you're totally allowed. – mustachioed Aug 25 '18 at 22:52
  • So, is there no way? – Erika Aug 25 '18 at 22:56
  • There is a way, and I posted the answer in the first comment. – FoulFoot Aug 25 '18 at 22:59
  • I believe that you didn't understood, i want inherit user session without doing the login again, the code in the first comment didn't worked – Erika Aug 25 '18 at 23:01
  • where are you passing username and password? – unixmiah Aug 25 '18 at 23:10
  • You may want to check here: https://stackoverflow.com/questions/1121280/how-to-let-curl-use-same-cookie-as-the-browser-from-php – FoulFoot Aug 25 '18 at 23:11
  • @unixmiah I don't want perform login, just get connected with my local session. – Erika Aug 25 '18 at 23:17
  • @FoulFoot I'll check about when get close home – Erika Aug 25 '18 at 23:17
  • @FoulFoot I've tried all scripts on this thread, not worked. I'm not automatically signed in – Erika Aug 26 '18 at 02:04
  • @Erika, check for Facebook APIs. – Rafael Aug 26 '18 at 05:51
  • First I would try logging in via cURL without using a cookie, i.e. including your username and password. Once you've accomplished that, then see about passing the session information. – FoulFoot Aug 26 '18 at 13:16
  • _“What I'm doing wrong? ”_ - this: _“I'm trying load facebook content with CURL”_ Facebook does not want you to do that, so they have measures in place against it, of course. If you want to interact with content, users or anything else on Facebook in any automated way - then use their APIs. Everything else is against their ToS to begin with. – CBroe Aug 27 '18 at 06:56

1 Answers1

-2

php is server side and your server run your php code and after that return the output to browser. you need use in iframe for example for show facebook timeline.

Fox
  • 103
  • 11