【问题标题】:Facebook: Can I add an event to a page as the pageFacebook:我可以将事件添加到页面作为页面吗
【发布时间】:2012-05-16 01:59:03
【问题描述】:

我只是一个页面的管理员,并编写了一个脚本来向该页面添加事件。我可以使用我自己的帐户并允许该应用程序管理我的页面并将事件添加到该页面。但我希望我的脚本添加事件,例如我将登录到页面并将事件发布为页面。我如何在 PHP 中做到这一点 - 我目前对所有会话、令牌和密钥有点困惑:-|

问候 丹尼斯

【问题讨论】:

  • stackoverflow.com/questions/5209233/… 刚刚为另一个问题发布了一些信息(最终不是他的答案 - 但它应该对您有所帮助)本质上,您授权应用程序管理具有离线权限的页面(应用程序令牌不会过期)然后您查询用户帐户以获取 Pages 令牌(本质上,应用程序令牌允许您获取用户对页面的管理员权限的令牌)然后您使用该令牌作为页面发布到页面...
  • 添加了我指出的另一个答案的缩写版本。基本上如果您更改密码或令牌过期,您将需要更新它...但下面的答案应该让您进入正确的方向..

标签: php facebook events


【解决方案1】:

如果您将自己添加为页面的负责人,那么您输入的任何内容都会反映为页面的名称(如果我没记错的话)。

【讨论】:

  • 要通过脚本完成,您必须使用通过用户应用令牌从用户帐户获取的页面令牌:)
  • 我的经验也是如此。虽然,现在他们可以选择将 facebook 作为“页面”浏览。不过,我认为 lilsizzo 是正确的。
【解决方案2】:

要发布为页面,您需要获取用户页面管理员令牌....

Page Authentication 的缩写版本:(添加了offline_access) 来自http://developers.facebook.com/docs/authentication/

通过管理权限和离线访问获取令牌:(使用 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... 在浏览器中,您将看到重定向 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);


?>

【讨论】:

  • 谢谢,没错。根据您的回答,我的方式是/是使用我的 inifite_session_key 获取 accessToken 并使用此令牌通过请求 graph-api 来获取我的所有帐户。在返回的账户中,我搜索了目标页面,并使用该页面的 accessToken 将事件作为页面发布到页面上。
  • 你明白了!哈哈,现在为什么 facebook 不得不让这个过程如此破解......我知道第二个令牌有助于识别代表特定页面的应用程序 - 但仍然......在很多层面上,他们本可以让这个过程更容易..
猜你喜欢
  • 2023-03-16
  • 1970-01-01
  • 2012-03-09
  • 2010-11-25
  • 2013-06-27
  • 2014-06-25
  • 2011-11-05
  • 1970-01-01
  • 2021-06-11
相关资源
最近更新 更多