Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Bonjour,
j'utilise le code ci-dessous pour d'une part s'identifier auprès de youtube et d'autre part pour renvoyer un commentaire sur une vidéo. Lien test
j'ai installé à la racine de mon site ZendFrameWork 1.12......j'avoue être néophyte mais je voudrais résoudre ce souci. j'ai emprunté le code à ce lien
Code en question:
<?php // start a new session session_start(); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( // realpath(APPLICATION_PATH . '/../library'), realpath('../common/zend/library'), get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); //AuthSub Functions function getAuthSubRequestUrl() { $next = 'http://www.businessbourse.com/tests.php'; // I have modified this for the sake of this question - it actually has a real url here normally $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } function getAuthSubHttpClient() { if (!isset($_GET['token']) ){ echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>'; return; } else if (isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); } $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); return $httpClient; } // Comment stuff if($httpClient != '' && isset($_POST['btn_submit'])) { $comment = $_POST['comment']; $videoEntry = $yt->getVideoEntry('QQoFLrZ5C3M'); $newComment = $yt->newCommentEntry(); $newComment->content = $yt->newContent()->setText($comment); // post the comment to the comments feed URL for the video $commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl(); $updatedVideoEntry = $yt->insertEntry($newComment, $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry'); } // End Comment Stuff ?> <!DOCTYPE HTML> <head> <title>UStream Test</title> <style> .comment { background-color: red; height: 100px; width: 500px; color: white; font-weight: bold; } </style> </head> <body> <div id="wrap"> <div id="authsub"> <?php if($httpClient == '' && !isset($_GET['token'])) { ?> <a href="<?=getAuthSubRequestUrl()?>">Authenticate</a><?php } elseif(!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $httpClient = getAuthSubHttpClient(); $_SESSION['httpClient'] = $httpClient; } else { $httpClient = $_SESSION['httpClient']; echo 'You are authenticated!'; } // if($httpClient == '') $httpClient = getAuthSubHttpClient(); // if($httpClient == '') echo '<br />empty'; else echo '<br />not empty'; ?> </div><br /><br /><br /><br /><br /> <?php /*********Creates YouTube Instance***********/ $applicationId = '#######################'; $clientId = '##############################'; $developerKey = 'AI39si6gCxCr6_xpjjDcgH7YkrlrfvHajRCyHdPex7C4RGWAUXc7CJcBBMLqHEoW__I5QGcPgyP7nvATmCojhRNrZ4eK3HZKcA'; $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); $commentFeed = $yt->getVideoCommentFeed('QQoFLrZ5C3M'); /********************************************/ ?> <div id="comment_form"> <form action="http://www.businessbourse.com/tests.php" method="post"> <input type="text" name="comment" placeholder="Enter your comment" /> <input type="submit" name="btn_submit" /> </form> </div> <?php foreach ($commentFeed as $commentEntry) { echo '<div class="comment">'; echo $commentEntry->title->text . "\n"; echo $commentEntry->content->text . "\n\n\n"; echo '</div><br />'; } ?> </div> </body>
Le problème, c'est qu'après m'être identifié avec succès, dès que je veux poster mon commentaire, j'ai ce message d'erreur :
Fatal error: Call to a member function getVideoEntry() on a non-object in /htdocs/public/www/tests.php on line 55
et si je reviens à la page précédente, je trouce ceci:
You are authenticated!
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpExcep<code type="php"></code>tion' with message 'Argument is not an instance of Zend_Http_Client.' in /htdocs/public/www/Zend/Gdata/YouTube.php:231 Stack trace: #0 /htdocs/public/www/Zend/Gdata/YouTube.php(212): Zend_Gdata_YouTube->setHttpClient(Object(__PHP_Incomplete_Class), '675765237623', '987348763498537...', 'AI39si7KdFT8_t4...') #1 /htdocs/public/www/tests.php(116): Zend_Gdata_YouTube->__construct(Object(__PHP_Incomplete_Class), '675765237623', '987348763498537...', 'AI39si7KdFT8_t4...') #2 {main} thrown in /htdocs/public/www/Zend/Gdata/YouTube.php on line 231
Si quelqu'un peut m'aider à résoudre ce bug, j'en serais ravi.
Merci
Dernière modification par donovanes (31-12-2012 11:09:21)
Hors ligne
Bonjour,
La variable $yt n'est pas une instance de Zend_Gdata_YouTube();
Ton script
[lang=php] $comment = $_POST['comment']; // manque ici $yt = new Zend_Gdata_YouTube(); $videoEntry = $yt->getVideoEntry('QQoFLrZ5C3M'); $newComment = $yt->newCommentEntry();
Exemple doc Zend http://framework.zend.com/manual/1.12/e … utube.html
[lang=php] $yt = new Zend_Gdata_YouTube(); $videoEntry = $yt->getVideoEntry('abc123813abc'); // we don't know the video ID in this example, but we do have the URL $commentFeed = $yt->getVideoCommentFeed(null, $videoEntry->comments->href);
Bon j'me suis pas attardé sur le reste du script ...
Dernière modification par us2rn4m2 (31-12-2012 13:02:50)
Hors ligne
Bonjour us2rn4m2,
peux tu m'aider à modifier ce qui bug dans le code afin de tester ?
je te remercie pour ton aide.
Dernière modification par donovanes (31-12-2012 13:02:19)
Hors ligne
J'viens d'editer mon precedent message.
Commence deja par rajouter cette instruction $yt = new Zend_Gdata_YouTube(); a l'endroit indiquer
[lang=php] $comment = $_POST['comment']; $yt = new Zend_Gdata_YouTube(); // <- ici $videoEntry = $yt->getVideoEntry('QQoFLrZ5C3M'); $newComment = $yt->newCommentEntry();
Tu testes. (J'reviendrais un peu plus tard ...)
Dernière modification par us2rn4m2 (31-12-2012 13:11:52)
Hors ligne
je viens d'ajouter l'instruction $yt = new Zend_Gdata_YouTube(); à l'endroit que tu m'as indiqué.
je viens de tester et j'obtiens ce résultat en retour: Lien test
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 401 <HTML> <HEAD> <TITLE>User authentication required.</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>User authentication required.</H1> <H2>Error 401</H2> </BODY> </HTML> ' in /htdocs/public/www/Zend/Gdata/App.php:714 Stack trace: #0 /htdocs/public/www/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('POST', 'https://gdata.y...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 /htdocs/public/www/Zend/Gdata/App.php(905): Zend_Gdata->performHttpRequest('POST', 'https://gdata.y...', Array, '<atom:entry xml...', 'application/ato...') #2 /htdocs/public/www/Zend/Gdata/App.php(980): Zend_Gdata_App->post(Object(Zend_Gdata_YouTube_CommentEntry), 'https://gdata.y...', NULL, NULL, Array) #3 /htdocs/public/www/tests.php(62): Zend_Gdata_App->insertEntry(Object(Zend_Gdata_YouTube_CommentEntry), 'https://gdata.y...', 'Zend_Gdata_YouT...') #4 {main} thrown in /htdocs/public/www/Zend/Gdata/App.php on line 714
et si je reviens à la page précédente, j'obtiens ceci:
You are authenticated!
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Argument is not an instance of Zend_Http_Client.' in /htdocs/public/www/Zend/Gdata/YouTube.php:231 Stack trace: #0 /htdocs/public/www/Zend/Gdata/YouTube.php(212): Zend_Gdata_YouTube->setHttpClient(Object(__PHP_Incomplete_Class), 'AIzaSyCEVTjJhDR...', '289360870856.ap...', 'AI39si6gCxCr6_x...') #1 /htdocs/public/www/tests.php(116): Zend_Gdata_YouTube->__construct(Object(__PHP_Incomplete_Class), 'AIzaSyCEVTjJhDR...', '289360870856.ap...', 'AI39si6gCxCr6_x...') #2 {main} thrown in /htdocs/public/www/Zend/Gdata/YouTube.php on line 231
Hors ligne
Bon j'reviens vite fait !
Tout d'abord tu devrais ameliorer ton Anglais parce que le script que t'as copié contient des erreurs dont le developpeur avait fait part. Il dit en dernière ligne : Can you see where I am going wrong here?, ce qui peut etre traduit par Pouvez-vous voir ou ce que je me suis trompé ?
Alors soit tu trouves un script qui a fait ces preuves, sinon ben.. on est le 31 Dec tu devras donc voir avec la doc Zend en attendant.
Bien entendu j'reviendrais sur ton post
Hors ligne
Merci us2rn4m2,
je compte sur toi.
Hors ligne
Bonjour us2rn4m2 et Bonne Année 2013,
Bonne Année 2013 à tous
j'ai trouvé ce code ci-dessous qui me semble mieux construit:
<?php session_start(); ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); function getAuthSubRequestUrl(){ $next = 'http://www.businessbourse.com/testsbis.php'; $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } function getAuthSubHttpClient(){ if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){ echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>'; return; } else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); } $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); return $httpClient; } function auth($videoId){ $applicationId = "applicationId"; $clientId = "clientId"; $developerKey="developerKey"; $httpClient = getAuthSubHttpClient(); $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); } require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path Zend_Loader::loadClass('Zend_Gdata_YouTube'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_App_Exception'); $yt = new Zend_Gdata_YouTube(); $yt->setMajorProtocolVersion(2); $videoFeed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/api/users/BusinessBourseBB/uploads'); $vidId = 'X85nZyVNE8Q'; if(isset($_POST['comment'])){ $comment=$_POST['comment']; } foreach ($videoFeed as $videoEntry) { if($videoEntry->getVideoId()==$vidId){ auth(); $vidTitle = htmlentities($videoEntry->getVideoTitle(), ENT_QUOTES, 'UTF-8'); //COMMENT if(isset($comment)){ if($comment!=''){//ONLY SEND COMMENT TO YOUTUBE IF A COMMENT HAS BEEN SET $newComment = $yt->newCommentEntry(); $newComment->content = $yt->newContent()->setText($comment); // post the comment to the comments feed URL for the video $commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl(); $updatedVideoEntry = $yt->insertEntry($newComment, $commentFeedPostUrl,'Zend_Gdata_YouTube_CommentEntry'); } } } } ?> <html> <head></head> <body> <h1><?php echo $vidTitle; ?></h1> <form id="comments" name="comments" action="" method="POST"> <textarea type="textarea" name="comment" id="comment" rows="5" cols="4"></textarea> <input type="submit" value="Post Comment" /> </form> </body> </html>
Cependant j'ai cette erreur ci-dessous après voulu publier un commentaire:
Warning: Missing argument 1 for auth(), called in /htdocs/public/www/testsbis.php on line 48 and defined in /htdocs/public/www/testsbis.php on line 25
selon le développeur de ce code , le auth()) n'est pas placé au bon endroit mais avant l'echoing video entry comme expliqué à ce lien:
peux tu m'aider à résoudre ce problème ?
Ici le lien test
Dernière modification par donovanes (01-01-2013 12:13:58)
Hors ligne
oui us2rn4m2,
Je vais regarder ce que tu me proposes.........
Hors ligne
Pour poster un commentaire
[lang=php] $email = 'boite@mail.com'; $passwd = '************'; try { $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'youtube'); } 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->exception() . "\n"; } $y = new Zend_Gdata_YouTube($client, 'MyCompany-MyApp-1.0', null, 'DEVELOPER-KEYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); $newCommentEntry = $y->newCommentEntry(); $newCommentEntry->content = $y->newContent()->setText('Hello'); $videoEntry = $y->getVideoEntry('abcxyz123'); $commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl(); $y->insertEntry($newCommentEntry, $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry');
Dernière modification par us2rn4m2 (12-01-2013 10:15:03)
Hors ligne