Re: [fw-general] Zend_Gdata problem

1 message Options
Embed this post
Permalink
Jochen Hartmann

Re: [fw-general] Zend_Gdata problem

Reply Threaded More More options
Print post
Permalink
On Wed, Jul 2, 2008 at 10:50 AM, Jochen Hartmann <[hidden email]> wrote:

> Hi,
>
> 403's similar to 401s are authentication related. For the YouTube API,
> a 403 is usually thrown if the developer key is not valid. Looking at
> your code below, and i know you added 'x'es to your developer key but
> it looks a little bit short.
>
> I would recommend modifying the code to include error handling so you
> can troubleshoot the response:
>
> [ keep your code as is ]
> ...
> $query = $yt->newVideoQuery('http://gdata.youtube.com/feeds/standardfeeds/top_rated');
> $query->setTime('today');
>
> try {
>
> $videoFeed = $yt->getVideoFeed($query);
>
> } catch (Zend_Gdata_App_HttpException $httpException) {
>   print 'ERROR : '. $httpException->getMessage()  .
>                   ' HTTP details <br />' .
>                   ($httpClient->getLastResponse() ?
> $httpClient->getLastResponse()->getBody() : 'No response from the
> server');
>  // if there is no specific HttpException,
>  // then just examine the regular exception
> } catch (Zend_Gdata_App_Exception $e) {
>   echo $e->getMessage()."<hr>";
> }
>
> On Wed, Jul 2, 2008 at 10:38 AM, Ahmed Abdel-Aliem <[hidden email]> wrote:
>> the same happened also when i tried to access youtube
>>
>> i get this error :
>>
>> exception 'Zend_Gdata_App_HttpException' with message 'Expected response
>> code 200, got 403' in /home/me2resh/www/pdf/library/Zend/Gdata/App.php:286
>> Stack trace: #0 /home/me2resh/www/pdf/library/Zend/Gdata/App.php(132):
>> Zend_Gdata_App::import('http://gdata.yo...', Object(Zend_Http_Client),
>> 'Zend_Gdata_YouT...') #1 /home/me2resh/www/pdf/library/Zend/Gdata.php(110):
>> Zend_Gdata_App->getFeed('http://gdata.yo...', 'Zend_Gdata_YouT...') #2
>> /home/me2resh/www/pdf/library/Zend/Gdata/YouTube.php(136):
>> Zend_Gdata->getFeed('http://gdata.yo...', 'Zend_Gdata_YouT...') #3
>> /home/me2resh/www/pdf/application/default/controllers/IndexController.php(43):
>> Zend_Gdata_YouTube->getVideoFeed(Object(Zend_Gdata_YouTube_VideoQuery)) #4
>> /home/me2resh/www/pdf/library/Zend/Controller/Action.php(502):
>> IndexController->indexAction() #5
>> /home/me2resh/www/pdf/library/Zend/Controller/Dispatcher/Standard.php(293):
>> Zend_Controller_Action->dispatch('indexAction') #6
>> /home/me2resh/www/pdf/library/Zend/Controller/Front.php(914):
>> Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
>> Object(Zend_Controller_Response_Http)) #7
>> /home/me2resh/www/pdf/html/index.php(35): Zend_Controller_Front->dispatch()
>> #8 {main}
>>
>>
>> and here is my code :
>>
>>
>> $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
>> $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
>>                                           $username = '[hidden email]',
>>                                           $password = 'xxxxxxxxxxxxxx',
>>                                           $service = 'youtube',
>>                                           $client = null,
>>                                           $source = 'MySource', // a short
>> string identifying your application
>>                                           $loginToken = null,
>>                                           $loginCaptcha = null,
>>                                           $authenticationURL);
>>
>>                                           $myDeveloperKey =
>> 'Mh0Fb8tQFHIt/1MK0Un0xxxxxxxxxxxxxx';
>>
>> $httpClient->setHeaders('X-GData-Key', "key=${myDeveloperKey}");
>>                                             $yt = new
>> Zend_Gdata_YouTube($httpClient);
>>
>>
>> $query =
>> $yt->newVideoQuery('http://gdata.youtube.com/feeds/standardfeeds/top_rated');
>> $query->setTime('today');
>> $videoFeed = $yt->getVideoFeed($query);
>>
>> i got the code from the manual, i dunno why it is not working with me
>>
>> On Mon, Jun 30, 2008 at 9:19 PM, Jochen Hartmann <[hidden email]>
>> wrote:
>>>
>>> Ahmed,
>>>
>>> A 401 is typically returned when you are not properly authenticated.
>>> Are you sure that your credentials are valid?
>>> You may consider printing out the full response:
>>>
>>> ...
>>>
>>> } catch (Zend_Gdata_App_HttpException $httpException) {
>>>
>>>    print 'ERROR : '. $httpException->getMessage()  .
>>>                    ' HTTP details <br />' .
>>>                    ($httpClient->getLastResponse() ?
>>> $httpClient->getLastResponse()->getBody() : 'No response from the
>>> server');
>>>
>>>
>>>  // if there is no specific HttpException,
>>>
>>>  // then just examine the regular exception
>>>
>>> } catch (Zend_Gdata_App_Exception $e) {
>>>
>>>    echo $e->getMessage()."<hr>";
>>> }
>>>
>>>
>>>
>>> On Fri, Jun 27, 2008 at 8:00 PM, Ahmed Abdel-Aliem <[hidden email]>
>>> wrote:
>>> > hi all,
>>> > i am running the below code to retrieve list of calendars from google
>>> > calendar, but when i run it i get this error :
>>> >
>>> > Error: Expected response code 200, got 401
>>> >
>>> > here is the code :
>>> >
>>> >
>>> > //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>> > $email = '[hidden email]';
>>> > $passwd = 'xxxxxxxxxx';
>>> > try {
>>> >    $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd);
>>> > } catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
>>> >     echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
>>> >     echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
>>> > } catch (Zend_Gdata_App_AuthException $ae) {
>>> >    echo 'Problem authenticating: ' . $ae->getMessage() . "\n";
>>> > }
>>> > $service = new Zend_Gdata_Calendar($client);
>>> >
>>> > try {
>>> >     $listFeed= $service->getCalendarListFeed();
>>> > } catch (Zend_Gdata_App_Exception $e) {
>>> >     echo "Error: " . $e->getMessage();
>>> > }
>>> > echo "<h1>Calendar List Feed</h1>";
>>> > echo "<ul>";
>>> > foreach ($listFeed as $calendar) {
>>> >     echo "<li>" . $calendar->title . " (Event Feed: " . $calendar->id .
>>> > ")</li>";
>>> > }
>>> > echo "</ul>";
>>> >
>>> >
>>> > //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>>> >
>>> > anybody can help me with that ??
>>> >
>>> > thanks in advance.
>>> >
>>> > --
>>> > Ahmed Abdel-Aliem
>>
>>
>>
>> --
>> Ahmed Abdel-Aliem
>