summaryrefslogtreecommitdiff
path: root/bin/fb-user-token.php
blob: c78abfc7821ab375d2c4985c06668a0f26a75387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

$basePath = dirname(__FILE__);
$configFile = $basePath . '/../config/facebook.json';

$config = json_decode(file_get_contents($configFile), TRUE);
$firstLink =
    'https://graph.facebook.com/oauth/client_code?' .
    http_build_query([
        'access_token' => $config['user_token'],
        'client_id' => $config['app_id'],
        'client_secret' => $config['app_secret'],
        'redirect_uri' => 'http://rss.emkael.info/facebook.php'
    ]);
$firstResponse = json_decode(file_get_contents($firstLink));

$secondLink =
    'https://graph.facebook.com/oauth/access_token?' .
    http_build_query([
        'client_id' => $config['app_id'],
        'code' => $firstResponse->code,
        'redirect_uri' => 'http://rss.emkael.info/facebook.php'
    ]);
$secondResponse = json_decode(file_get_contents($secondLink));

$config['user_token'] = $secondResponse->access_token;

print json_encode($config);

?>