Reputation: 284
I want to post to a page named XY and it should appear on the page directly and not as a posting from another user (the admin). This is the code I adapted from http://qscripts.blogspot.de/2011/02/post-to-your-own-facebook-account-from.html but this posts to the area for other users not to the main page. If I replace the page-id number by "me" it posts to admins page and correctly to the main area.
#!/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;
}
Upvotes: 0
Views: 224
Reputation: 20753
While posting on a page, if you use the access token of a user/admin the post will be published as the user/admin but not as a page itself.
To post on a page as a page itself you should use the page access token. To get a page access token you need the permission manage_pages
and you can make a call to /{user-id}/accounts
. This way you will get the access token for your page.
Now the good thing is that you can have a page access token that never expires! I've explained with steps here: https://stackoverflow.com/a/18322405/1343690
Hope it helps. Good luck!
Upvotes: 4