0

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;
}
Stefan Müller
  • 274
  • 2
  • 13

1 Answers1

4

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!

Community
  • 1
  • 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • Thanks! And for wrapping this GET I need another perl script, right? – Stefan Müller Mar 30 '14 at 20:37
  • Ah and `manage_pages` is set within facebook, right? If I am the admin of this page, I should be fine, shouldn't I? – Stefan Müller Mar 30 '14 at 20:38
  • Why the other script? You can add that in your current script only. The permission needs to be set before getting the token. I'm not sure how exactly are you getting the token (using login flow or graph api explorer) – Sahil Mittal Mar 31 '14 at 03:39
  • OK. It works, but if I want to remove the posting, FB complains: The content you requested cannot be displayed right now. It may be temporarily unavailable, the link you clicked on may have expired, or you may not have permission to view this page. Hm. I can hide the stuff though. – Stefan Müller Mar 31 '14 at 08:43
  • How are you removing the posting? You can remove the posts with the `\DELETE` `/post_id`. – Sahil Mittal Mar 31 '14 at 08:45
  • No, I tried to do this on the facebook page itself. With the facebook gui. – Stefan Müller Mar 31 '14 at 08:47
  • Of course you can delete. There could be some bug with facebook. Trust me, you can delete those posts with facebook gui and also with the api – Sahil Mittal Mar 31 '14 at 08:50