/** Uses the Graph API to get likes for a URI @param $uri the URI to check @return like count */ function like_count($uri) { $res = radix_http::get('http://graph.facebook.com/?ids=' . rawurlencode($uri)); if ($res['info']['http_code'] == 200) { $res = json_decode($res['body'], true); return intval($res[$uri]['shares']); } }
/** @param $code the OAuth2 Code @param $page the Redirect to URI @see https://developers.google.com/accounts/docs/OAuth2WebServer */ function auth_token($code, $page) { $uri = 'https://accounts.google.com/o/oauth2/token'; $arg = array('code' => $code, 'client_id' => $this->_client_id, 'client_secret' => $this->_client_sk, 'redirect_uri' => $page, 'grant_type' => 'authorization_code'); // POST it $ret = radix_http::post($uri, $arg); return $ret; }
/** @param $a the token passed back from the oAuth Provider, typically $_GET['oauth_token'] */ public function getAccessToken($a = null) { $uri = self::TOKEN_ACCESS_URI; $arg = array('client_id' => $this->_oauth_client_id, 'client_secret' => $this->_oauth_client_secret, 'grant_type' => 'authorization_code', 'redirect_uri' => $a['redirect_uri'], 'code' => $a['code']); $res = radix_http::get($uri . '?' . http_build_query($arg)); radix::dump($res); $ret = json_decode($res['body'], true); return $ret; }
/** Easy Wrapper for Fetch */ function api($uri, $post = null) { $uri = sprintf('%s/%s', self::API_URI, trim($uri, '/')); if (!empty($post)) { die('I do not handle this yet'); } $res = radix_http::get($uri, array('Authorization: ' . $this->_access_token)); $type = strtok($res['info']['content_type'], ';'); if ($type == 'application/json') { $res = json_decode($res['body'], true); } return $res; }
/** @param $a the token passed back from the oAuth Provider, typically $_GET['oauth_token'] */ public function getAccessToken($arg) { $uri = self::ACCESS_TOKEN_URI; // try { // $res = $this->_oauth->getAccessToken($uri); // // radix::dump($res); // } catch (Exception $e) { // radix::dump($this->_oauth->debugInfo); // return false; // } // return $res; $arg = http_build_query(array('grant_type' => 'authorization_code', 'client_id' => $this->_oauth_client, 'client_secret' => $this->_oauth_client_secret, 'code' => $_GET['code'], 'redirect_uri' => $arg['redirect_uri'])); $res = radix_http::post($uri, $arg); $res = json_decode($res['body'], true); // if ($res['info']['http_code'] == 200) { // } else return $res; }
/** Easy Wrapper for Fetch */ function api($uri, $post = null, $head = null) { $verb = 'GET'; // $post = array(); // $post = array( // 'format' => 'json', // ); $uri = self::API_URI . ltrim($uri, '/') . '?access_token=' . $this->_access_token; // $ret = $this->fetch($uri,$post,$verb,$head); if (!empty($post)) { die('I do not handle this yet'); } $res = radix_http::get($uri); if ($res['info']['content_type'] == 'application/json') { $res = json_decode($res['body'], true); } return $res; }
public function statApplication($sid) { $api = sprintf('/Applications/%s.json', $sid); $res = radix_http::get($this->_base . $api); $ret = json_decode($res['body'], true); return $ret; }