这个问题在某种程度上是 Perl FaceBook::Graph API 特有的,一般可能与 Facebook Graph 无关。我正在尝试做的是尝试使用 Perl 和 FaceBook::Graph 模块发布照片。模块文档(http://metacpan.org/pod/Facebook::Graph)表明我需要“publish_stream”权限发布照片,但这会生成“必须使用活动访问令牌来查询有关当前用户。” 错误,而常规消息发布没有错误。在使用访问令牌调试器检查我的令牌时,我得到以下信息:
App ID: [removed]: [removed]
Metadata: []
User ID: [removed] : [removed]
Issued: Unknown
Expires: 1372705200 (in about an hour)
Valid: True
Origin: Web
Scopes: create_note photo_upload publish_actions publish_stream share_item status_update user_photos video_upload
不幸的是,“Facebook::Graph::Publish::Photo”模块的 CPAN 文档有点缺乏,我找不到完整的 Perl 示例来发布不引用相同代码的照片。下面是我更完整的示例代码:
#note: this is not the complete code I'm using, quite a few non-FB related lines left out for simplicity
#create the
my $FBHandle=Facebook::Graph->new(
app_id => $TargetFBAppID, #passed in as an arg
secret => $TargetFBAppSecret, #passed in as an arg
postback => $TargetFBAppPostBack #passed in as an arg
);
#make sure this is valid when passing it in
my $AccessTokenResult=$FBHandle->access_token($FBAccessToken); #passed in as an arg, generated by FB's Access Token Debugger
if(!$AccessTokenResult) {
$FaultString="No FB access token returned";
} else {
#do the image post
my $PostHash=$FBHandle->add_photo()
->set_source($TempFileResultHash->{"fullpath"}) #works out to "C:/Tools/apache-tomcat-7.0.22/webapps/service_api/temp/FacebookBroadcast-F38365F5-6D00-1014-9DBD-87D476B3CC17"
->set_message($OptionsHash->{"message"}||"") #passed in from args
;
#add_post works, but not add_photo
#my $PostHash=$FBHandle->add_post()
# ->set_message($OptionsHash->{"message"}||"") #passed in from args
#;
#send it
my $PostResultHash=$PostHash->publish(); #need "publish_stream" priv for this to work
die Data::Dumper::Dumper($PostResultHash); #dump the result
} #end if
任何人都知道我可能会出错的地方吗?
进一步编辑:FaceBook::Graph add_note() 和 add_link() 方法也可以正常工作,只要将正确的 privs 添加到访问令牌中,但 add_photo() 仍然会引发错误。