Users can Upload video on single Youtube Channel with or without authentication

*爱你&永不变心* 提交于 2020-01-24 19:26:05

问题


I am making a program that will upload video to my youtube channel by any user. But it generates error. My code is as follows:-

   require_once 'Zend/Loader.php';
   Zend_Loader::loadClass('Zend_Gdata_YouTube');
   Zend_Loader::loadClass('Zend_Gdata_AuthSub');
   Zend_Loader::loadClass('Zend_Gdata_App_Exception');

   Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

   $authenticationURL= 'https://www.google.com/accounts/ClientLogin';

   $client = "";

    $email = 'theprofessional1992@gmail.com';

  $passwd = '*******************';

   try {

     $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');

   } 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";

}

Error :- Notice: Undefined offset: 1 in C:\wamp\www\Yt\zdata\demos\Zend\Gdata\YouTubeVideoApp\Zend\Gdata\ClientLogin.php on line 150

Even i don't know how this functionality will be made.

Please any help ?


回答1:


Note: The YouTube Data API (v2) has been officially deprecated as of March 4, 2014

With YouTube Data API (v3) you can not upload using username and password.
If you want to upload a video to youtube, you have to use these libs:
https://github.com/google/google-api-php-client
https://github.com/youtube/api-samples/tree/master/php
https://github.com/youtube/api-samples/blob/master/php/resumable_upload.php

Of course if you don't want authentication each upload process you can use refresh token.

$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/oauth2/v3/token');
$client->setAccessType('offline');

An refresh token will be include in api response. Save it into the database. Remember that you only can get the refresh token at the first time. if you lose it you will have to revoke your application https://security.google.com/settings/security/permissions?pli=1

Now with refresh token you can get access token anytime automatically:

$client->refreshToken($refreshToken);
$accessToken = $client->getAccessToken();


来源:https://stackoverflow.com/questions/31397297/users-can-upload-video-on-single-youtube-channel-with-or-without-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!