向fb graph_api调用添加错误消息的打印输出

时间:2014-03-31 06:38:45

标签: facebook perl facebook-graph-api

我从http://qscripts.blogspot.de/2011/02/post-to-your-own-facebook-account-from.html复制了一个脚本,并尝试将其扩展为打印错误消息。不知怎的,这不起作用。我试图阅读文档,但graph_api似乎不属于任何加载的模块。那么如何才能获得有关定位失败原因的信息?

#!/usr/bin/perl -I/opt/ActivePerl-5.16/site/lib/

# http://qscripts.blogspot.de/2011/02/post-to-your-own-facebook-account-from.html

use strict;
use warnings;
use open qw(:std :utf8);
use LWP::Simple;
use YAML;
use JSON;
use URI;
use utf8;

my $access_token = 'top secret';

# Post to a specific page: profile specified

graph_api('1484559088426611/feed', {
  access_token => $access_token,
  message      => 'Hello World! I’m posting Facebook updates from a script!',
  description  => 'You want to create a script to read messages and post status updates to your own '
                . 'Facebook account, but you find the official documentation confusing and '
                . 'you aren’t sure where to start. Search no more because here you’ll find '
                . 'the easiest way to do just this.',
  method       => 'post'
});


exit 0;

sub graph_api {
  my $uri = new URI('https://graph.facebook.com/' . shift);
  $uri->query_form(shift);
  my $resp = get("$uri");
  return defined $resp ? decode_json($resp) : undef;
}

0 个答案:

没有答案