使用SQL数据库为组页面创建Facebook事件,并使用图形API进行发布

时间:2014-04-04 20:36:38

标签: php sql facebook facebook-graph-api facebook-php-sdk

我一直试图发布已经在mySQL数据库中创建的事件,并使用facebook的图形api将其发布到组页面。我能够在代码中发布一个创建的数组,但我想发布一个我从POST命令中提取的数组。这就是我所拥有的。

public function get_event()
{
    require_once 'application/php-sdk/facebook.php';

    $config = array(
        'appId' => '1407968509465242',
        'secret' => '***********************',
        'cookie' => false,
        'fileUpload' => true 
    );

            $id = $_POST['eventsDrp'];
            $this->load->model('mdl_facebook_event');
            $output = $this->mdl_facebook_event->get_event($id);
            print_r ($output);


    $facebook = new Facebook($config);         
    // Set the current access token to be a long-lived token.
    $facebook->setExtendedAccessToken();
    $access_token = $facebook->getAccessToken();

        $page_id = '594922100555123';

        $page_access_token = '*******************';

        // Declare the variables we'll use to demonstrate
        // the new event-management APIs
        $event_id = 0;
        $event_name = "New Event API Test Event";
        $event_start = '2012-04-24T22:01:00+0000';
        $event_privacy = "SECRET"; // We'll make it secret so we don't annoy folks.

        // We'll create an event in this example.
        // We'll need create_event permission for this.
        $params = array(
          'name' => $event_name,
          'start_time' => $event_start,
          'privacy_type' => $event_privacy,
          'access_token' => $page_access_token,
          'page_id' => $page_id //where $page_id is the ID of the page you are managing
        );

        // Create an event
        $ret_obj = $facebook->api("/$page_id/events", 'POST', $output);
        if(isset($ret_obj['id'])) {
          // Success
          $event_id = $ret_obj['id'];
          echo ('Event ID: ' . $event_id);
        } else {
          echo ("Couldn't create event.");
        }

        // Convenience method to print simple pre-formatted text.
        function printMsg($msg) {
           echo "<pre>$msg</pre>";
        }

我正在尝试从$output发布数组。我试图从$params发帖,一切正常。当我尝试从$ output发布时,我得到致命错误:

  

未捕获OAuthException:无效令牌:“594922100555123”。已经指定了ID。

0 个答案:

没有答案