-
-
Save Eckankar/e882c1235a49f44c7af0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
access_token: LANG_TOKEN_HER | |
app_id: 'APPID_HER' | |
app_secret: APPSECRET_HER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.012; | |
use warnings; | |
use YAML::Tiny; | |
use LWP::Simple; | |
use JSON qw/from_json/; | |
=head1 NAME | |
C<facebook_ext_token.pl> - Extends an access token received from Facebook to last longer. | |
=cut | |
my $configuration_file = '/srv/infoscreen.coq.dk/facebook.yaml'; | |
my $yaml = YAML::Tiny->read($configuration_file); | |
my $config = $yaml->[0]; | |
my $url = 'https://graph.facebook.com/v2.3/oauth/access_token?'. | |
'grant_type=fb_exchange_token&'. | |
'client_id=' . $config->{app_id} . '&' . | |
'client_secret=' . $config->{app_secret} . '&' . | |
'fb_exchange_token=' . $ARGV[0]; | |
my $response = get($url); | |
print "$response\n"; | |
$response = from_json($response); | |
my ($access_token) = $response->{access_token}; | |
$config->{access_token} = $access_token; | |
print $ARGV[0] . "\n"; | |
print $access_token . "\n"; | |
$yaml->write($configuration_file); | |
print "Hvis du ikke fik fejl er token'en opdateret nu.\n"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.012; | |
use warnings; | |
use Mojolicious::Lite; | |
use CHI; | |
use DateTime::Format::ISO8601; | |
use Facebook::Graph; | |
use YAML::Tiny; | |
use experimental qw(smartmatch autoderef); | |
use Try::Tiny; | |
use utf8::all; | |
my $fb_config_file = '/srv/infoscreen.coq.dk/facebook.yaml'; | |
my $yaml = YAML::Tiny->read($fb_config_file); | |
my $config = $yaml->[0]; | |
my $cache = CHI->new( driver => 'Memory', global => 1 ); | |
get '/fb/dikumemes' => sub { | |
my $c = shift; | |
my $res = $cache->compute("fb_dikumemes", "20 minutes", sub { | |
my $fb; | |
try { | |
$fb = Facebook::Graph->new( | |
app_id => $config->{app_id}, | |
app_secret => $config->{app_secret}, | |
access_token => $config->{access_token}, | |
); | |
} catch { | |
return { error => "Facebook creds er udløbet." }; | |
# print "Mine Facebook credentials er udløbet. :(\n"; | |
# print STDERR "En eller anden log ind som concieggs på fjæseren, gå ind på https://developers.facebook.com/tools/explorer/702475036512546/ og tryk 'Get Access Token' i toppen.\n"; | |
# print STDERR "Kør så følgende fra en commandline: $ext_token_script <token>"; | |
return; | |
}; | |
my @group_feed = grep { $_->{link} =~ qr{facebook\.com/photo\.php} } @{ $fb->fetch('1676857065872315/feed')->{data} }; | |
my @res; | |
for my $element (@group_feed) { | |
my $elm = $fb->fetch($element->{object_id}); | |
$element->{imagedata} = $elm; | |
push(@res, $element); | |
} | |
return { elements => \@res }; | |
}); | |
$c->res->headers->add('Access-Control-Allow-Origin' => '*'); | |
$c->render(json => $res); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment