function buffer_connect(&$a) { if (isset($_REQUEST["error"])) { $o = t('Error when registering buffer connection:') . " " . $_REQUEST["error"]; return $o; } // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); // Define the needed keys $client_id = get_config('buffer', 'client_id'); $client_secret = get_config('buffer', 'client_secret'); // The callback URL is the script that gets called after the user authenticates with buffer $callback_url = $a->get_baseurl() . "/buffer/connect"; $buffer = new BufferApp($client_id, $client_secret, $callback_url); if (!$buffer->ok) { $o .= '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>'; } else { logger("buffer_connect: authenticated"); $o .= t("You are now authenticated to buffer. "); $o .= '<br /><a href="' . $a->get_baseurl() . '/settings/connectors">' . t("return to the connector page") . '</a>'; set_pconfig(local_user(), 'buffer', 'access_token', $buffer->access_token); } return $o; }
<?php session_start(); require 'buffer.php'; $client_id = ''; $client_secret = ''; $callback_url = 'http://127.0.0.1/callback'; $buffer = new BufferApp($client_id, $client_secret, $callback_url); if (!$buffer->ok) { echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>'; } else { $profiles = $buffer->go('/profiles'); if (is_array($profiles)) { foreach ($profiles as $profile) { $buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id)); } } }