/**
  * Format a POST call to the bit.ly API.
  *
  * @param $uri
  *   URI to call.
  * @param $fields
  *   Array of fields to send.
  */
 function bitly_post($endpoint, $params)
 {
     $result = array();
     $url = bitly_oauth_api . $api_endpoint;
     $output = json_decode(bitly_post_curl($url, $params), true);
     $result = $output['data'][str_replace('/', '_', $api_endpoint)];
     $result['status_code'] = $output['status_code'];
     return $result;
 }
Beispiel #2
0
/**
 * Returns an OAuth access token as well as API users for a given code.
 *
 * @param $code
 *   The OAuth verification code acquired via OAuth’s web authentication
 *   protocol.
 * @param $redirect
 *   The page to which a user was redirected upon successfully authenticating.
 *
 * @return
 *   An associative array containing:
 *   - login: The corresponding bit.ly users username.
 *   - api_key: The corresponding bit.ly users API key.
 *   - access_token: The OAuth access token for specified user.
 *
 * @see http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/oauth/access_token
 */
function bitly_oauth_access_token($code, $redirect)
{
    $results = array();
    $url = bitly_oauth_access_token . "access_token";
    $params = array();
    $params['client_id'] = bitly_clientid;
    $params['client_secret'] = bitly_secret;
    $params['code'] = $code;
    $params['redirect_uri'] = $redirect;
    $output = bitly_post_curl($url, $params);
    $parts = explode('&', $output);
    foreach ($parts as $part) {
        $bits = explode('=', $part);
        $results[$bits[0]] = $bits[1];
    }
    return $results;
}