コード例 #1
0
         $url .= '&machine_id=' . $machine_id;
     }
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $data = curl_exec($ch);
     $result = @json_decode($data, true);
     if (!$result || !isset($result['access_token'])) {
         die('Failed to get client access token from API, please press back and try again: ' . $data);
     }
     $machine_id = isset($result['machine_id']) ? $result['machine_id'] : $machine_id;
     // todo - save machine id along with access_token, use in future requests.
     $facebook->update('facebook_token', $result['access_token']);
     $facebook->update('machine_id', $machine_id);
     // success!
     // now we load in a list of facebook pages to manage and redirect the user back to the 'edit' screen where they can continue managing the account.
     $facebook->graph_load_available_pages();
     redirect_browser(module_social_facebook::link_open($social_facebook_id));
 } else {
     if ($facebook->get('facebook_app_id') && $facebook->get('facebook_app_secret')) {
         // we connect using our own app id / secret
         require_once 'includes/plugin_social_facebook/inc/facebook.php';
         $settings = array('appId' => $facebook->get('facebook_app_id'), 'secret' => $facebook->get('facebook_app_secret'));
         $facebook_api = new Facebook($settings);
         //echo $facebook_api->getLoginUrl(array());
         if (isset($_REQUEST['login_completed']) && !empty($_REQUEST['login_completed'])) {
             // we have logged in, time to test it out!
             ini_set('display_errors', true);
             ini_set('error_reporting', E_ALL);
             $_SESSION['fb_' . $facebook->get('facebook_app_id') . '_access_token'] = $_REQUEST['login_completed'];
             $facebook_api->setAccessToken($_REQUEST['login_completed']);
             $access_token = $facebook_api->getAccessToken();