#!/usr/bin/env perl

#use strict;
use warnings;
use utf8;
use Pg;
use CGI;

#json系モジュール
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use JSON qw/encode_json decode_json/;
use Encode;
use JSON;
use URI::Escape;

#cookie関連
use CGI::Cookie;


my $q = new CGI;
my $conn = Pg::connectdb("dbname=naoto host=localhost user=naoto password=9513nnn7010");

my $userInfoUrl = 'https://graph.facebook.com/100002047373754';


print "Content-Type: text/html; charset=UTF-8\n\n";

print "<html><head></head><body>\n";

&getJson($userInfoUrl);

print $userInfoUrl;

print "</body></html>";

	exit(0);



sub getJson{
	my $getUrl = shift @_;
	my $request = HTTP::Request->new(GET => $getUrl);
		$request->referer($referer);
	my $ua = LWP::UserAgent->new;
	my $response = $ua->request($request);

	if ($response->is_success) {
		my $json = $response->content;
		my $fromJson = from_json($json);
		my $uid = $fromJson->{'id'};
		my $uname = $fromJson->{'name'};
		print "$uid";
		print "<br>";
		print "$uname";
		print "<br>";
	}
else {
	warn 'Failed to request to WEB API.', "\n";
	}
}
