diff --git a/README.md b/README.md index 4a24c14..8751fe5 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,26 @@ The __FACEBOOK_USER_TOKEN__ is generated via the graph explorer page https://developers.facebook.com/tools/explorer/ using an user that is said to be over 18 of age to support crawling of all types of pages. - - - +#### Crawling with test users #### + +Extracts all the access tokens of your test users with **testuser.php** script: +```Shell +$ php testuser.php +Write access token of test user #1 into TOKEN.1 +Write access token of test user #2 into TOKEN.2 +Write access token of test user #3 into TOKEN.3 +Write access token of test user #4 into TOKEN.4 +``` + +Check extracted tokens: +```Shell +$ ls TOKEN.* +TOKEN.1 TOKEN.2 TOKEN.3 TOKEN.4 +``` + +launch the crawler with the token files: +```Shell +$ php agent.php token_file\=TOKEN.1 +``` ***Happy crawling!!*** diff --git a/agent.php b/agent.php index b60008c..c2bf120 100644 --- a/agent.php +++ b/agent.php @@ -21,8 +21,14 @@ //Parse command line arguments as GET variables parse_str(implode('&', array_slice($argv, 1)), $_GET); + +if(!isset($_GET['token_file'])) + $tokenFile = dirname($_SERVER['SCRIPT_FILENAME'])."/TOKEN"; +else + $tokenFile = $_GET['token_file']; + if(!isset($_GET['token'])) - print "No token provided, will try to read from the file: ".dirname($_SERVER['SCRIPT_FILENAME']) . "/TOKEN instead.".PHP_EOL; + print "No token provided, will try to read from the file: ".$tokenFile." instead.".PHP_EOL; else $token['access_token'] = $_GET['token']; renewAccessToken(); @@ -252,8 +258,7 @@ function crawl($currentPost, $facebook) { } function renewAccessToken() { - GLOBAL $facebook, $token; - $tokenFile = dirname($_SERVER['SCRIPT_FILENAME']) . "/TOKEN"; + GLOBAL $facebook, $token, $tokenFile; if(file_exists($tokenFile)) { $file = fopen($tokenFile, "r+"); $token['access_token'] = fgets($file); diff --git a/testuser.php b/testuser.php new file mode 100644 index 0000000..1821965 --- /dev/null +++ b/testuser.php @@ -0,0 +1,22 @@ + APPID, + 'secret' => APPSEC, +)); + +$access_token = $facebook->getAccessToken(); +$accounts = $facebook->api("/".APPID."/accounts/test-users?access_token=$access_token"); + +$id=1; +foreach($accounts['data'] as $account) { + $filename="TOKEN.$id"; + print "Write access token of test user #$id into $filename\n"; + file_put_contents($filename, $account['access_token']); + $id++; +} + +?>