开发者

Facebook: Can I add an event to a page as the page

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


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 ).


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


?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜