/** * Provides a given user’s 100 most popular links based on click traffic in the * past hour, and the number of clicks per link. * * @param $access_token * The OAuth access token for the user. * * @return * A multidimensional numbered associative array containing: * - user_hash: The corresponding bit.ly user identifier. * - clicks: Number of clicks on this link. * * @see http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/realtime_links */ function bitly_v3_user_realtime_links($access_token) { // $results = bitly_v3_user_realtime_links('BITLY_SUPPLIED_ACCESS_TOKEN'); $results = array(); $url = bitly_oauth_api . "user/realtime_links?format=json&access_token=" . $access_token; $output = json_decode(bitly_get_curl($url)); if (isset($output->{'data'}->{'realtime_links'})) { foreach ($output->{'data'}->{'realtime_links'} as $realtime_links) { $rec = array(); $rec['clicks'] = $realtime_links->{'clicks'}; $rec['user_hash'] = $realtime_links->{'user_hash'}; array_push($results, $rec); } } return $results; }
/** * Format a GET call to the bit.ly API. * * @param $endpoint * bit.ly API endpoint to call. * @param $params * associative array of params related to this call. * @param $complex * set to true if params includes associative arrays itself (or using <php5) * * @return * associative array of bit.ly response * * @see http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/validate */ function bitly_get($endpoint, $params, $complex = false) { $result = array(); if ($complex) { $url_params = ""; foreach ($params as $key => $val) { if (is_array($val)) { // we need to flatten this into one proper command $recs = array(); foreach ($val as $rec) { $tmp = explode('/', $rec); $tmp = array_reverse($tmp); array_push($recs, $tmp[0]); } $val = implode('&' . $key . '=', $recs); } $url_params .= '&' . $key . "=" . $val; } $url = bitly_oauth_api . $endpoint . "?" . substr($url_params, 1); } else { $url = bitly_oauth_api . $endpoint . "?" . http_build_query($params); } //echo $url . "\n"; $result = json_decode(bitly_get_curl($url), true); return $result; }
/** * Returns the significant languages for the bitly link * * @param $access_token * The OAuth access token for the user. * * @return * An associative array containing * - the link as the key * - the language as the value * * @see http://dev.bitly.com/data_apis.html */ function bitly_v3_link_language($access_token, $link) { $results = array(); $url = bitly_oauth_api . "link/language?access_token=" . $access_token . "&link=" . urlencode($link); $output = json_decode(bitly_get_curl($url)); if (isset($output->{'data'}->{'languages'})) { foreach ($output->{'data'}->{'languages'} as $key => $val) { $results[$key] = $val; } } return $results; }