2014-03-30 51 views
0

我想发布到名为XY的页面,它应该直接显示在页面上,而不是作为来自其他用户(管理员)的发布。这是我从http://qscripts.blogspot.de/2011/02/post-to-your-own-facebook-account-from.html改编的代码,但是这会发布到其他用户的区域而不是主页面。如果我用“我”替换页面ID号码,它会发布到管理页面并正确显示到主区域。作为此页面发布消息到页面墙(不是管理员)

#!/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'; 

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; 
} 

回答

4

虽然张贴在一个页面上,如果您使用的用户的访问令牌/ ADMIN的职位将被发布为用户/管理员,但不是作为一个页面本身。

要将页面张贴为页面本身,您应该使用page access token。要获得页面访问令牌,您需要获得许可manage_pages,并且您可以致电/{user-id}/accounts。这样你将获得你的页面的访问令牌。

现在的好处是,你可以有一个页面访问令牌永不过期!我已经在这里解释了步骤:https://stackoverflow.com/a/18322405/1343690

希望它有帮助。祝你好运!

+0

谢谢!为了包装这个GET,我需要另一个perl脚本,对吧? –

+0

啊和'manage_pages'设置在脸书里,对吧?如果我是这个页面的管理员,我应该没问题,不是吗? –

+0

为什么其他脚本?您只能将其添加到当前脚本中。获取令牌之前需要设置权限。我不确定你是如何得到令牌的(使用登录流或图形API浏览器) –

相关问题