douyou2234 2013-10-17 10:11
浏览 14
已采纳

为什么我不能将事件添加为页面?

I'm trying to add an event to a page in the name of the page. I'm the admin of the page and I found a lot of stuff to the topic, but, no matter what I do, it ends in the PHP Exception:

Uncaught Exception: You must be an admin of the specified page to perform the requested action.

I can add events with my app in my own profile. So, I think the problem is the Access Token. I tried several ways, but to me the best way seems to be:

  1. Open the Graph API Explorer
  2. Select my Application
  3. Request a new access code with permissions manage_pages, publish_actions, publish_stream, create_event
  4. Request /me/accounts
  5. Get the access_token from the page I want to post to and use it in my script

My test script, that works in my own profile:

require 'src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => $APPLICATION_ID,
  'secret' => $APPLICATION_SECRET,
  'cookie'     => false,
  'fileUpload' => true
));

$event_id = 0;
$event_name = "New Event API Test Event";
$event_start = '2013-12-04';
$event_privacy = "OPEN";

$ret_obj = $facebook->api('/'.$page_id.'/events?access_token='.$access_token, 'POST', 
array(
   'name' => $event_name,
   'start_time' => $event_start,
   'privacy_type' => $event_privacy,
   'location_id' => $location_id
));

if(isset($ret_obj['id'])) {
  echo 'Event with added. ID: ' . $ret_obj['id'];
} else {
  echo 'Couldn\'t create event';
}

What I did wrong?

  • 写回答

2条回答 默认 最新

  • dqg2269 2013-10-17 11:52
    关注

    You need a page access token.

    Page Access Token – These access tokens are similar to user access tokens, except that they provide permission to APIs that read, write or modify the data belonging to a Facebook Page. To obtain a page access token you need to start by obtaining a user access token and asking for the manage_pages permission. Once you have the user access token you then get the page access token via the Graph API.

    Doc: https://developers.facebook.com/docs/facebook-login/access-tokens/

    Then use GET /me/accounts to get the access token associated to your page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么