You are here

function _media_youtube_get_auth_sub_http_client in Media: YouTube 6

Convenience method to obtain an authenticted Zend_Http_Client object.

Return value

Zend_Http_Client An authenticated client.

1 call to _media_youtube_get_auth_sub_http_client()
_media_youtube_check_upload in includes/media_youtube.api.inc
Check the upload status of a video.

File

includes/media_youtube.api.inc, line 90
Miscellaneous API function calls for Media: YouTube.

Code

function _media_youtube_get_auth_sub_http_client($youtube_username = NULL, $youtube_password = NULL) {
  $youtube_username = isset($youtube_username) ? $youtube_username : media_youtube_variable_get('youtube_username');
  $youtube_password = isset($youtube_password) ? $youtube_password : media_youtube_variable_get('youtube_password');
  _media_youtube_set_include_path();
  $path = media_youtube_zend_path();
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin', $path);
  Zend_Loader::loadClass('Zend_Gdata_App_Exception', $path);
  Zend_Loader::loadClass('Zend_Gdata_App_HttpException', $path);
  try {
    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($youtube_username, $youtube_password, 'youtube', NULL, MEDIA_YOUTUBE_APP_ID, NULL, NULL, MEDIA_YOUTUBE_AUTH_URL);
  } catch (Zend_Gdata_App_Exception $e) {
    $message = 'Could not obtain authenticated Http client object: @error.';
    $variables = array(
      '@error' => $e
        ->getMessage(),
    );
    watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
    return;
  } catch (Zend_Gdata_App_HttpException $e) {
    $message = 'Could not obtain authenticated Http client object: @error.';
    $variables = array(
      '@error' => $e
        ->getMessage(),
    );
    watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
    return;
  }
  $httpClient
    ->setHeaders('X-GData-Key', 'key=' . media_youtube_variable_get('api_key'));
  return $httpClient;
}