3
votes

I am doing a project where I need to import Facebook Page feeds. For accessing Facebook page feeds, I need a page_access_token and to generate page_access_token I need User access token.

Here my question is

1.How to generate this User_access_token using CURL ? Most of the solution requires APP_KEY & APP_SECRET. Is it not possible to get user_access_token without any APP ?

  1. Once I get the User_access_token how do I use it to get Page access Token using CURL.
2

2 Answers

3
votes

You can´t get ANY Token without an App, but you don´t need to program anything in order to get a User Token. These articles explain everything in detail:

For example, you can use the API Explorer to select your App and generate User Tokens.

0
votes

Wrong question, No tokens are needed

I just tried it and it took me less than 5 minutes, never having scraped FB in the past. I saved the page to my Server and brought up the page using my URL and it looked just like if I were on FB.

If a Browser can load the page with JavaScript disabled, then you can too.

You have to use https://m.facebook.com/, JavaScript is not required on their mobile site.

What you want to do, is not difficult at all.

Just go there in your Browser and copy the cookies key values into the Cookie: HTTP request header. Mine are x'ed out.

<?php
$request = array();
$request[] = 'Host: m.facebook.com';
$request[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:39.0) Gecko/20100101 Firefox/39.0';
$request[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$request[] = 'Accept-Language: en-US,en;q=0.5';
$request[] = 'Accept-Encoding: gzip, deflate';
$request[] = 'DNT: 1';
$request[] = 'Cookie: datr=x; fr=x; lu=x s=xx; csm=x; xs=xx; c_user=x; p=-2; act=x; presence=x; noscript=1';
$request[] = 'Connection: keep-alive';
$request[] = 'Pragma: no-cache';
$request[] = 'ache-Control: no-cache';
$url = 'https://m.facebook.com/';
 $ch = curl_init($url);

  curl_setopt($ch, CURLOPT_ENCODING,"");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_FILETIME, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT,100);
  curl_setopt($ch, CURLOPT_FAILONERROR,true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $request);

  $data = curl_exec($ch);
  if (curl_errno($ch)){
      $data .= 'Retreive Base Page Error: ' . curl_error($ch);
  }
  else {
    $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
    $responseHeader = substr($data,0,$skip);
    $data= substr($data,$skip);
    $info = curl_getinfo($ch);
    $info = var_export($info,true);
   }
      while(true){  // get cookies from response header
        $s = strpos($head,'Set-Cookie: ',$e);
        if (!$s){break;}
        $s += 12;
        $e = strpos($head,';',$s);
        $cookie = substr($head,$s,$e-$s) ;
        $s = strpos($cookie,'=');
        $key = substr($cookie,0,$s);
        $value = substr($cookie,$s);
        $cookies[$key] = $value;

      }

     $cookie = '';  // format cookies for next request header
     $show = '';
     $head = '';
     $delim = '';
     foreach ($cookies as $k => $v){
       $cookie .= "$delim$k$v";
       $delim = '; ';
     }

  $fp = fopen("fb.html",'w');
  fwrite($fp,"$data\n$info\n$responseHeader");
  fclose($fp);

readfile('fb.html');