我只是管理页面并编写脚本以向该页面添加事件。我可以使用自己的帐户,并允许该应用管理我的页面并将事件添加到该页面。但我希望我的脚本添加事件,例如我将登录到页面并将事件作为页面发布。如何在PHP中执行此操作 - 我目前对所有会话,令牌和密钥有点困惑: - |
问候 丹尼斯
答案 0 :(得分:1)
如果您将自己添加为该页面的负责人,则无论您输入什么内容都会反映为页面的名称(如果我没有记错的话)。
答案 1 :(得分:0)
要发布为网页,您需要获取用户页面管理员令牌....
页面身份验证的缩写版本:(已添加offline_access) 来自http://developers.facebook.com/docs/authentication/
获取带有管理权限和offline_access的令牌:(使用YOUR_APP_ID和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
验证页面后,您将被重定向到YOUR_URL ... 在浏览器中,您将看到重定向网址,哈希,访问令牌,到期... 复制'token ='和'& expires = 0'之间的所有内容(如果它没有expires = 0你没有进行离线访问预备)
<?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);
?>