Mercurial > nebulaweb3
comparison default/assets/vendors/theme-widgets/vendor/mute/facebook/example/writing-questions.php @ 0:1d038bc9b3d2 default tip
Up:default
author | Liny <dev@neowd.com> |
---|---|
date | Sat, 31 May 2025 09:21:51 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1d038bc9b3d2 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Writing Questions via Graph API | |
5 * | |
6 * @author Xavier Barbosa | |
7 * @since 13 February, 2013 | |
8 * @link https://developers.facebook.com/blog/post/635/ | |
9 **/ | |
10 | |
11 use Mute\Facebook\App; | |
12 | |
13 /** | |
14 * Default params | |
15 **/ | |
16 | |
17 $question = 'What are you doing this weekend?'; | |
18 $options = json_encode(array('Hiking','Watching a movie','Hacking')); | |
19 | |
20 $page_id = 'YOUR_PAGE_ID'; | |
21 $app_id = 'YOUR_APP_ID'; | |
22 $app_secret = 'YOUR_APP_SECRET'; | |
23 $my_url = 'YOUR_URL'; | |
24 | |
25 /** | |
26 * The process | |
27 **/ | |
28 | |
29 $app = new App($app_id, $app_secret); | |
30 | |
31 $code = $_REQUEST["code"]; | |
32 | |
33 echo '<html><body>'; | |
34 | |
35 if (empty($code)) { | |
36 $dialog_url = $app->getOAuth()->getCodeURL($my_url, array('manage_pages')); | |
37 | |
38 echo "<script> top.location.href=" . json_encode($dialog_url) . "</script>"; | |
39 } | |
40 else { | |
41 $params = $app->getOAuth()->getAccessToken($code); | |
42 $response = $app->get('me/accounts', array( | |
43 'access_token' => $params['access_token'], | |
44 )); | |
45 $accounts = $response['data']; | |
46 | |
47 // Find the access token for the Page | |
48 $page_access_token = ''; | |
49 foreach($accounts as $account) if($account['id'] == $page_id) { | |
50 $page_access_token = $account['access_token']; | |
51 break; | |
52 } | |
53 | |
54 // Post the question to the Page | |
55 $post_question_url = $app->post($page_id . '/questions', array( | |
56 'question' => $question, | |
57 'options' => $options, | |
58 'allow_new_options' => false, | |
59 'access_token' => $page_access_token, | |
60 )); | |
61 | |
62 print_r($post_question_url); | |
63 } | |
64 | |
65 echo '</body></html>'; |