用户可以通过或不通过身份验证在单个YouTube频道上上传视频 [英] Users can Upload video on single Youtube Channel with or without authentication

查看:393
本文介绍了用户可以通过或不通过身份验证在单个YouTube频道上上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序,任何用户都可以将视频上传到我的youtube频道.但这会产生错误.我的代码如下:-

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

}

错误:-注意:未定义的偏移量:1英寸 C:\ wamp \ www \ Yt \ zdata \ demos \ Zend \ Gdata \ YouTubeVideoApp \ Zend \ Gdata \ ClientLogin.php 在第150行上

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.

请帮忙吗?

推荐答案

注意:YouTube数据API(v2)已于2011年正式弃用 2014年3月4日

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

使用YouTube数据API(v3),您不能使用用户名和密码上传.
如果要将视频上传到youtube,则必须使用以下库:
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

当然,如果您不希望每个上传过程都进行身份验证,则可以使用刷新令牌.

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');

刷新令牌将包含在api响应中.将其保存到数据库中.请记住,您只能在第一时间获得刷新令牌.如果丢失,则必须撤消您的应用程序 https://security.google. com/settings/security/permissions?pli = 1

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();

这篇关于用户可以通过或不通过身份验证在单个YouTube频道上上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆