OSDN Git Service

split config library
[mubot4fb/mubot4fb.git] / get_facebook_accesscode.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use Facebook::Graph;
5 use Config::Any;
6 use Hash::Merge::Simple;
7 use Data::Recursive::Encode;
8 use Data::Dumper;
9
10 my %cfg;
11
12 my $config_name = $ARGV[0] || 'not_found';
13
14 my $cfg = {};
15 my $config_path = ['/etc/mubot4fb/'.$config_name,
16                    $ENV{HOME} . '/.mubot4fb/'. $config_name,
17                    $ENV{PWD} . '/mubot4fb_' . $config_name];
18
19 my $c = Config::Any->load_stems({stems => $config_path,  use_ext => 1, flatten_to_hash => 1});
20 foreach my $i (keys %$c) {
21         $cfg = Hash::Merge::Simple->merge($cfg, $c->{$i});
22 }
23 die 'missing config file' unless (keys %$cfg);
24
25 die 'missing some config parameters should be defined (irc_server, fb_app_id, fb_app_secret, fb_access_code, fb_page_id fb_postback_url)'
26     if (!defined $cfg->{'fb_app_id'});
27
28 $cfg = Data::Recursive::Encode->decode('utf8', $cfg);
29
30 my $fb = Facebook::Graph->new(app_id   => $cfg->{'fb_app_id'},
31                               secret   => $cfg->{'fb_app_secret'},
32                               postback => $cfg->{'fb_postback_url'});
33 my $page_id = $cfg{'page_id'};
34
35 my $uri_t = $fb->authorize->extend_permissions(qw(offline_access publish_stream status_update))->uri_as_string;
36 print $uri_t . "\n";
37
38 print "\n\n↑この表示されてる uri をブラウザにつっこむと access_code が得られる redirect さきの url に code パラメタとしてくっついてくるので それを設定ファイルの access_code パラメータにコピペ...\n";
39 print "ただし そのブラウザで facebook にログインしている必要あり\n";
40
41 exit;