0

我曾经使用此代码上传视频:

    try {
    $ytConfigData = App_SiteSettings::get('yt');
    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($ytConfigData->user,$ytConfigData->password, 'youtube');
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
    echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
    echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
    exit;
} catch (Zend_Gdata_App_AuthException $ae) {
    echo 'Problem authenticating: ' . $ae->exception() . "\n";
    exit;
}
$yt = new Zend_Gdata_YouTube($httpClient,
                                 null,//$applicationId,
                                 null,//$clientId,
                                 $ytConfigData->devkey);
$myVideoEntry= new Zend_Gdata_YouTube_VideoEntry()

现在我 通过 Google 验证失败。原因:错误的身份验证

我没有在我的 gmail 帐户上启用两步验证

我也尝试过使用 https://code.google.com/p/google-api-php-client/ 但只有一个示例来显示上传视频没有示例如何加载视频:(所以你能给我如何通过我的脚本在 youtube 上上传视频?提前谢谢。

4

1 回答 1

0

抱歉,一天后脚本再次运行,我不知道为什么:(新闻是,以防万一停止工作,我有备用方案:) 使用https://code.google.com/p/google-api -php-client/ 我发布它以防万一

$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$redirect = filter_var('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
  FILTER_SANITIZE_URL);

$client->setRedirectUri($redirect);

$youtube = new Google_YoutubeService($client);


if (isset($_GET['code'])) {
  if (strval($_SESSION['state']) !== strval($_GET['state'])) {
    die('The session state did not match.');
  }

  $client->authenticate();
  $_SESSION['token'] = $client->getAccessToken();
  header('Location: ' . $redirect);
}

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}

echo $_SESSION['token'];

if ($client->getAccessToken()) {
  try {
    $snippet = new Google_VideoSnippet();
$snippet->setTitle("Test title2");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1", "tag2"));
$snippet->setCategoryId("22");
$status = new Google_VideoStatus();
$status->privacyStatus = "private";
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status); 
$videoData = file_get_contents(ROOT_DIR.'/video-2012-11-23-23-24-45.mp4');
$r = $youtube->videos->insert("status,snippet", $video, array("data" => $videoData, "mimeType" => "video/mp4"));
于 2013-05-15T15:27:42.613 回答