Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

facebook - How to programmatically add an event to a page using Graph API?

Is it possible to programmatically add an event to a page using Facebook Graph API? If yes, what HTTP request shall be made?

For example, Startup Weekend has events on its Facebook page. These events can be added using Graph API Event object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE

Creating event with the API is no longer possible in v2.0+. Check: https://developers.facebook.com/docs/apps/changelog#v2_0


Yes it's possible.

Permissions:

  1. create_event
  2. manage_pages

So first you get the page id and its access token, through:

$facebook->api("/me/accounts");

The Result will be something like:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => Page Name
                    [category] => Website
                    [id] => XXXXXX
                    [access_token] => XXXXX
                )

            [1] => Array
                (
                    [name] => Page Name 2
                    [category] => Company
                    [id] => XXXXXXX
                    [access_token] => XXXXXXXX
                )
        )

)

UPDATE: To retrieve the page's access_token you could now call the page object directly like:

$page_info = $facebook->api("/PAGE_ID?fields=access_token");

The access token, if successful call, should be accessible: $page_info['access_token']

Now you get the Page ID and access token and use the events connection:

$nextWeek = time() + (7 * 24 * 60 * 60);
$event_param = array(
    "access_token" => "XXXXXXXX",
    "name" => "My Page Event",
    "start_time" => $nextWeek,
    "location" => "Beirut"
);
$event_id = $facebook->api("/PAGE_ID/events", "POST", $event_param);

And you are done! :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...