ZF-8028: Get the YoutubeUser from ClientLogin


Currently Youtube api provides authentication by [youtube-username, password] or by [gmail-useremail, gmail-password]. That's good, but sometimes makes troubles. Let's consider example: I logged in through ClientLogin by gmail-useremail and gmail-password. But further to deal with api I need specify youtube-username instead gmail-useremail. For instance, retrieving own videos Youtube api expects only youtube-username, not gmail-useremail. How can I get that youtube-username logging in by gmail account? I know the in this case returns YouTubeUser with Auth token ( see Zend_Gdata_ClientLogin::getHttpClient 146-153 ). But how can I get it in my code? It seems to me patching the ZF a little ( to save the YouTuberUser also with Auth token) is that way.



This patch allows to retrieve the internal Youtube username from auth requests (in case you are registered by gmail account and authenticated by gmail email/password).

There are couple notices here: - Retrieving ClientLogin instance you have to provide to Zend_Gdata_ClientLogin::getHttpClient $loginUri as ''…'' instead of '''' (the otherwise Youtube will not provide internal username) - Also in Zend_Gdata_ClientLogin::getHttpClient you have to provide $client as instance of Zend_Gdata_YoutubeHttpClient (instances of Zend_Gdata_HttpClient don't know how to get internal youtube username) or to leave as null (in this case Zend_Gdata_ClientLogin::getHttpClient automatically creates required client type)

I've attached patch that can fetch Youtube internal username, let's see an example

$authenticationURL = "";
$client = new Zend_Gdata_YoutubeHttpClient();

$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
                                         "", $password,
                                         $service = "youtube",
                                         $loginToken = null,
                                         $loginCaptcha = null,
if ( $httpClient instanceof Zend_Gdata_YoutubeHttpClient ){
   $internalYoutubeUsername = $httpClient->getActualYoutubeUsername();
   // $internalYoutubeUsername is something like 'youtubeuser', so you can do
   $api = new Zend_Gdata_YouTube( $httpClient, $applicationId, $clientId, $developerKey );
   $api->getUserUploads ( $internalYoutubeUsername );
   // though last is same as $api->getUserUploads ( 'default' );

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.