0

I'm just admin of a page and programming a script to add events to that page. I could use my own account and allow the app to manage my pages and add event to that page. But I want that my Script adds the event such as I would be logged in to the page and publish the event as the page. How can I do this in PHP - I'm currently a little bit confused by all the sessions, tokens and keys :-|

Greetings Denis

Denis
  • 173
  • 1
  • 2
  • 6
  • http://stackoverflow.com/questions/5209233/facebook-api-how-to-publish-to-page-feed-while-user-is-offline-without-offline-a/5227048#5227048 Just postd some of the info for another question (ended up not being his answer - but it should help you) Essentially, you authorize the app to manage the pages with offline premisssions (app token doesnt expire) Then you query the users accoutn for the Pages token (essentially the app token allows you to get a token for the users admin rights to the page) you then use that token to publish to the page as the page... – CarpeNoctumDC Mar 09 '11 at 09:24
  • Added an abbreviated version of the other answer i pointed you to.. Essentially if you change the password or the token expires you will need to update it... But the answer below should get you in the right direction.. – CarpeNoctumDC Mar 09 '11 at 09:52

2 Answers2

1

if you added yourself as the person in charge for the page, whatever you put in would be reflected as the page's name ( if I am not mistaken ).

Oleksi
  • 12,947
  • 4
  • 56
  • 80
lilsizzo
  • 366
  • 2
  • 18
  • To have it be done by a script you have to use the page's token aquired from the users account via the users app token :) – CarpeNoctumDC Mar 09 '11 at 09:22
  • My experience as well. Although, now they have an option of browsing facebook as "the page". Still, I think lilsizzo is correct. – Elad Lachmi Mar 09 '11 at 09:24
0

To publish as a page you need to get the user page admin token....

Abbreviated version of Page Authentication: (added offline_access) From http://developers.facebook.com/docs/authentication/

Get the token with manage premissions and offline_access: (update with YOUR_APP_ID and YOUR_URL

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages,offline_access&response_type=token

Once you authenticate the page, you will be redirected to YOUR_URL... In the browser you will see the redirect url, a hash, the access token, expires... copy everything between the 'token=' and '&expires=0' (if it doesnt have expires=0 you did not do offline access premissions)

<?php
require_once('facebook.php');

$app_id = "YOURAPPID";
$app_secret = "YOURSECRET";

$userAppToken = 'TOKENHERE!'; // from authentication
$pageID = '123456';


$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));


$token =  array(
    'access_token' => $userAppToken
);

// Get the user page admin tokens (account access info)
$userdata = $facebook->api('/me/accounts', 'GET', $token);

// Loop through the data and get the token for the page id..
foreach($userdata['data'] as $data) {
   if ($data['id'] == $pageID) {
      $pageAdminToken = $data['access_token'];
      continue;
   }
}

// THis is actually for a wall post, but just modify to whatever you want (you must have access_token as it is what authorizes the action for the page..    
// compile the post
$WallPost = array(
    'message' => 'Test post from my app!',
    'access_token' => $pageAdminToken
);  // you can also use 'picture', 'link', 'name', 'caption', 'description', 'source'....
    //http://developers.facebook.com/docs/reference/api/


// post to wall (feed is wall post, just update to whatever you want to publish to)
$response = $fb->api($pageID . '/feed','GET',$WallPost);


?>
CarpeNoctumDC
  • 1,760
  • 1
  • 12
  • 16
  • Thanks, thats right. According to your answer my way was/is to get an accessToken with my inifite_session_key and use this token to get all my accounts by requesting the graph-api. in the returned accounts I searched for the target page and used the accessToken for this page to post an event onto the page as the page. – Denis Mar 09 '11 at 11:18
  • You got it! LOL now why facebook had to make the process so cracked out... I get that the second token helps identify the app acting on the sepcific pages behalf - but still... On so many levels they could have made the process easier.. – CarpeNoctumDC Mar 09 '11 at 11:54