From ca014bcc03c4ffb9c0d1f4334001ddf8c45f22db Mon Sep 17 00:00:00 2001 From: CC Lien Date: Fri, 20 Dec 2013 21:02:38 +0000 Subject: [PATCH 1/4] allow to specify TOKEN filename with token_file option --- agent.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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); From b280b7c4ee72252ff24a6f109914c2c881707f32 Mon Sep 17 00:00:00 2001 From: CC Lien Date: Fri, 20 Dec 2013 21:33:10 +0000 Subject: [PATCH 2/4] Tool for extracting test user TOKENs --- testuser.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 testuser.php diff --git a/testuser.php b/testuser.php new file mode 100644 index 0000000..a03833b --- /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 of test user #$id into $filename\n"; + file_put_contents($filename, $account['access_token']); + $id++; +} + +?> From fec18de1a783302245325a002125c5ba7c65b699 Mon Sep 17 00:00:00 2001 From: CC Lien Date: Sat, 21 Dec 2013 05:48:40 +0800 Subject: [PATCH 3/4] Update README.md for usage of test user tool --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a24c14..3fc8f25 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 of test user #1 into TOKEN.1 +Write access of test user #2 into TOKEN.2 +Write access of test user #3 into TOKEN.3 +Write access 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!!*** From 1862c157c9ce80fb6da23882b872d5a6ee186f7e Mon Sep 17 00:00:00 2001 From: CC Lien Date: Fri, 20 Dec 2013 22:06:44 +0000 Subject: [PATCH 4/4] fix typo in messages --- README.md | 8 ++++---- testuser.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3fc8f25..8751fe5 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ be over 18 of age to support crawling of all types of pages. Extracts all the access tokens of your test users with **testuser.php** script: ```Shell $ php testuser.php -Write access of test user #1 into TOKEN.1 -Write access of test user #2 into TOKEN.2 -Write access of test user #3 into TOKEN.3 -Write access of test user #4 into TOKEN.4 +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: diff --git a/testuser.php b/testuser.php index a03833b..1821965 100644 --- a/testuser.php +++ b/testuser.php @@ -14,7 +14,7 @@ $id=1; foreach($accounts['data'] as $account) { $filename="TOKEN.$id"; - print "Write access of test user #$id into $filename\n"; + print "Write access token of test user #$id into $filename\n"; file_put_contents($filename, $account['access_token']); $id++; }