protected function wipe() { $cnf = static::get_conf(); $cnf->InstagramOAuthToken = null; $cnf->write(); header('Location: ' . SocialHelper::php_self()); }
public static function get_instagram() { if (!static::$instagram_instance) { $conf = static::get_conf(); static::$instagram_instance = new Instagram(array('apiKey' => $conf->InstagramApiKey, 'apiSecret' => $conf->InstagramApiSecret, 'apiCallback' => SocialHelper::php_self())); } return static::$instagram_instance; }
public function index() { // authorise $user = Member::currentUser(); if (!Permission::checkMember($user, 'ADMIN')) { return $this->httpError(401, 'You do not have access to the requested content'); } // grab the API Lib $facebook = static::get_facebook(); // the auth process authorises both a user and a page // it might pay to make this a seperate step in future if we decide to add user feeds as well as page feeds if (empty($this->conf->FacebookPageId)) { die('Facebook Page ID not supplied'); } // if there's a code in the request grab it $code = empty($_REQUEST['code']) ? null : $_REQUEST['code']; // if the code is empty shoot off to fb and grab one - it will redirect back here with a code if (empty($code)) { $dialog_url = static::getOAuthDialogURL(); header('Location: ' . $dialog_url); exit; } // so we've got a code now - lets do some more authorisation if (static::validate_crsf()) { // The user access token url $token_url = 'https://graph.facebook.com/oauth/access_token' . '?client_id=' . $this->conf->FacebookAppId . '&redirect_uri=' . urlencode(SocialHelper::php_self()) . '&client_secret=' . $this->conf->FacebookAppSecret . '&code=' . $code; // fetch and parse the response $response = file_get_contents($token_url); $params = null; parse_str($response, $params); // die if we didn't get the required info if (empty($params['access_token'])) { die('couldn\'t get user access token - are you logged in to the correct facebook account?'); } // save the user access token $this->conf->FacebookUserAccessToken = $params['access_token']; $this->conf->write(); // get the user ID associated with the access token and stash it for later $facebook->setDefaultAccessToken((string) $this->conf->FacebookUserAccessToken); $user = (object) static::get_facebook()->sendRequest('get', '/me')->getDecodedBody(); // die if we couldn't get an id if (empty($user->id)) { die('couldn\'t access user info'); } // save the user ID $this->conf->FacebookUserId = $user->id; $this->conf->write(); // get an access token for the page $page_info = $facebook->sendRequest('get', '/' . $this->conf->FacebookPageId . "?fields=access_token")->getDecodedBody(); // die if we didn't get the required info if (empty($page_info['access_token'])) { die('couldn\'t get page access token - are you logged in to the correct facebook account and an admin of page ' . $this->conf->FacebookPageId . '?'); } // save the page access token $this->conf->FacebookPageAccessToken = $page_info['access_token']; $this->conf->write(); // grab the site config $freshConf = SiteConfig::current_site_config(); // final output echo '<p>User ' . $this->conf->FacebookUserId . ($freshConf->FacebookUserAccessToken ? ' was authenticated' : ' was not authenticated') . '</p>'; echo '<p>Page ' . $this->conf->FacebookPageId . ($freshConf->FacebookPageAccessToken ? ' was authenticated' : ' was not authenticated') . '</p>'; exit; } else { die('crsf error'); } }
protected function access_token() { $this->tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token']; $this->tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret']; $code = $this->tmhOAuth->request('POST', $this->tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier'])); if ($code == 200) { $token = $this->tmhOAuth->extract_params($this->tmhOAuth->response['response']); $this->conf->TwitterOAuthToken = $token['oauth_token']; $this->conf->TwitterOAuthSecret = $token['oauth_token_secret']; $this->conf->TwitterUsername = $token['screen_name']; $this->conf->write(); unset($_SESSION['oauth']); header('Location: ' . SocialHelper::php_self()); } else { $this->addError(); } }