Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!!***
11 changes: 8 additions & 3 deletions agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions testuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// Get test users' access tokens of the app
require_once "./config/config.php";
require_once "./facebook-php/src/facebook.php";

$facebook = new Facebook(array(
'appId' => 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++;
}

?>