_____ _ _ _____ _____
/ ____| | | | | /\ | __ \_ _|
| | __ __ _ _ __ ___ ___| | ___| |_ / \ | |__) || |
| | |_ |/ _` | '_ ` _ \ / _ \ |/ _ \ __| / /\ \ | ___/ | |
| |__| | (_| | | | | | | __/ | __/ |_ / ____ \| | _| |_
\_____|\__,_|_| |_| |_|\___|_|\___|\__/_/ \_\_| |_____|
__ _ _ _ _ _
/ _| (_) | | (_) | |
| |_ _ __ _ ___ _ __ __| | |_ ___| |_
| _| '__| |/ _ \ '_ \ / _` | | / __| __|
| | | | | | __/ | | | (_| | | \__ \ |_
|_| |_| |_|\___|_| |_|\__,_|_|_|___/\__|
+-----------------------------------------+
| By Jamie Phan [Lovemelody]|
| https://www.jamiephan.net|
|tw.gamelet.com/user.do?username=jamiephan|
+-----------------------------------------+
GameletAPI friendlist provide API to access the friend list in Gamelet.com with multi-threading. Also providing CLI (Command Line Interface) and Web server for users.
Gamelet Discussion link: http://tw.gamelet.com/discussion.do?type=TALK&id=669754
git clone https://github.com/jamiephan/GameletAPI.friendlist.git
#Download the repository from github and clone to the current directory
cd GameletAPI.friendlist
#Enter the directory for friendlist
composer install
#Install the dependencies with composer
You can modify the following code to meet your needs, the following is just an simple example.
<?php
require 'includes/class.friendlist.php';
//Include the PHP class file, under includes/class.friendlist.php.
$username = "jamiephan";
//Define a username.
$friendlist = new GameletAPI_friendlist($username);
//Create a new object with the given username as string in constructor.
$friendlist->execute();
//Execute the process (Download and analyse the HTML).
if ($friendlist->error === false) {
//Check if there is any errors, such as non-existing username etc.
var_dump($friendlist->getFriendListArray);
//Dump the data.
} else {
echo $friendlist->error;
//Show the error message.
}
?>
Before $friendlist->execute()
:
$friendlist->setKey("userID", "userNickname")
- Allow users to set the index key for the array, the default setting areuserID
anduserNickname
. Only allow alphabetical letters.
After $friendlist->execute()
:
-
$friendlist->username
- Returns the initial request username (This is afterurldecode()
, converting%40
to@
). -
$friendlist->executeTime
- Returns the total execution time in seconds (The time that spent on downloading and analysing the HTML). -
$friendlist->getFriendListNumber
- Returns the total amount of friend.
Navigate to the command line tool folder under cli
cd cli
Enter php friendlist.php -h
to see the command line information.
Here is the copy from the help:
Usage: php friendlist.php
-u Specify username (ID).
-o Specify output file name. if not defined,
it will print out to terminal instead.
You can output as any file extension, but
this program will detect the value of .php,
.xml, .csv, .json, .txt, and output with
their representative format automatically.
-h Show helps and credits.
Examples: php friendlist.php -u jamiephan -o /home/folder/list.json
php friendlist.php -u 100000380302236%40facebook.com -o C:/folder/mylist.php
php friendlist.php -u 100000380302236@facebook.com -o ../output.txt
php friendlist.php -u lovemelody01 -o ../friends.xml
php friendlist.php -h
The tool will detect the file extension you had specified and output regarding to their format. The supported list are:
-
.xml - This will create a root element named
friendlist
. Each friend will wrap with afriend
tag, since XML does not support arrays. Example -
.json - This will create a json compatable object with the friend list array. Example
-
.csv - This will create a CSV object. Example
-
.php - This will create a PHP file with the array stored in, with the variable named
GameletAPI_friendlist
. You can dynamically include it in your projects (include "output.php";
, assume output.php if the file name). Example -
.txt - This will show all the information about the request, including execution time, date, number of friends etc. This format is designed for human readable and not meant to be used programatically. Example
IMPORTANT: All other extensions will considered into .txt
format. Example
The script had alerady configured to run as a webserver with URL routing, do not use it under command line interface.
To start using PHP build in server command:
php -S localhost:8080 -t webserver webserver/index.php
(8080
is the port number, change it as you desire.)
As the webserver using URL routing, some confuguations must be done with specific server.
Place a .htaccess
file under webserver/
with the content of:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Make sure that the httpd.conf
have configured AllowOverride All
for .htaccess
usage.
This config file assumes:
-
domain name (
server name
):example.com
-
PHP-FPM server port:
9000
In addition, you need to configure the path for error_log
, access_log
, root
.
server {
listen 80;
server_name example.com;
index index.php;
error_log /path/to/example.error.log;
access_log /path/to/example.access.log;
root /path/to/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
Create a file named web.config
and place under webserver/
with the content of:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Configure the lighthttpd with the following code:
url.rewrite-if-not-file = ("(.*)" => "/index.php/$0")
Open the webpage with the PHP engine running, assuming the host is localhost
and the port is 8080
.
http://localhost:8080
You should see an error message:
{
"error": "Please provide an username."
}
Now add a username to the query:
http://localhost:8080/jamiephan
If you see a list of usernames, then the server had configured properly.
As like the CLI application, the webserver also allows you to justify the output format. After /username
, append a /format
. Example: http://localhost:8080/jamiephan/xml
.
The supported formats are:
-
/json
-
/jsonp
(Please see additional info below) -
/xml
-
/csv
-
/txt
All other formats (including not specify) will be considered as /json
.
for more information, please see https://github.com/jamiephan/GameletAPI.friendlist#formats-for-cli.
The webserver also allow query parameters, the supported params are:
-
IDKey
- Set the key for ID, default:userID
-
NicknameKey
- Set the key for Nickname, default:userNickname
-
forceDownload
- This will force the file to be downloaded from the browser (it will keep the file extension as specified, but will only convertjsonp
intojs
). The file name isfriendlist-{username}.{format}
, for examplefriendlist-jamiephan.json
Example: http://localhost:8080/jamiephan/json?IDKey=userID&NicknameKey=userNickname
The sever also supports JSONP
callback. If you chosen /jsonp
, please also specify the callback function name.
callback
- Set the callback for JSONP, the default isfriendlist
;
Example: http://localhost:8080/jamiephan/jsonp?callback=console.log
The webserver code in this repo had been hosted in https://friendlist.jamiephan.net/. You can use it as to test out the parameters remotely, just replace http://localhost:8080
with https://friendlist.jamiephan.net
.
-
https://friendlist.jamiephan.net/jamiephan
- Show friends with the username
jamiephan
(Default using JSON).
- Show friends with the username
-
https://friendlist.jamiephan.net/100000380302236%40facebook.com/txt
- Show friends with the username
100000380302236%40facebook.com
and output a human readable format (txt
is not to be used programatically).
- Show friends with the username
-
https://friendlist.jamiephan.net/lovemelody01/xml?IDKey=ID&NicknameKey=Nickname
- Show friends with the username
lovemelody01
and output as json with the userID keyID
and userNickname keyNickname
.
- Show friends with the username
-
https://friendlist.jamiephan.net/lovemelody02/csv?forceDownload
- Show friends with the username
lovemelody02
and force the browser to download the filefriendlist-lovemelody02.csv
- Show friends with the username
-
https://friendlist.jamiephan.net/jamiephan/jsonp?callback=console.log
- show friends with the username
jamiephan
, output withJSON
and have the callback ofconsole.log
- show friends with the username