Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,谷歌数据API V3,上传到youtube_Php_Youtube - Fatal编程技术网

PHP,谷歌数据API V3,上传到youtube

PHP,谷歌数据API V3,上传到youtube,php,youtube,Php,Youtube,我正在尝试实现将视频上传到youtube的代码。我看到了一些关于这个主题的其他帖子,但我仍然无法让它发挥作用,而且我还没有足够的技能去弄清楚如何测试它,看看发生了什么。我也可以运行这段代码的框架,获取已经上传的内容,但我似乎无法上传视频。任何帮助都将不胜感激 <?php // Call set_include_path() as needed to point to your client library. require_once ($_SERVER["DOCUMENT_ROOT"].

我正在尝试实现将视频上传到youtube的代码。我看到了一些关于这个主题的其他帖子,但我仍然无法让它发挥作用,而且我还没有足够的技能去弄清楚如何测试它,看看发生了什么。我也可以运行这段代码的框架,获取已经上传的内容,但我似乎无法上传视频。任何帮助都将不胜感激

<?php

// Call set_include_path() as needed to point to your client library.
require_once ($_SERVER["DOCUMENT_ROOT"].'/src/Google_Client.php');
require_once ($_SERVER["DOCUMENT_ROOT"].'/src/contrib/Google_YouTubeService.php');
session_start();

/* You can acquire an OAuth 2 ID/secret pair from the API Access tab on the Google APIs Console
  <http://code.google.com/apis/console#access>
For more information about using OAuth2 to access Google APIs, please visit:
  <https://developers.google.com/accounts/docs/OAuth2>
Please ensure that you have enabled the YouTube Data API for your project. */
$OAUTH2_CLIENT_ID = 'someclient.apps.googleusercontent.com';
$OAUTH2_CLIENT_SECRET = 'some secret';

$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$redirect = filter_var('http://' . $_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']);
}
    print "line 38";
if ($client->getAccessToken()) {
    print "line 40";
    $snippet = new Google_VideoSnippet();
    $snippet->setTitle("Test title");
    $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);

    $error = true;
    $i = 0;

    try {
        $obj = $youTubeService->videos->insert("status,snippet", $video,
                                         array("data"=>file_get_contents("screencast.mp4"), 
                                        "mimeType" => "video/mp4"));
    } catch(Google_ServiceException $e) {
        print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage(). " <br>";
        print "Stack trace is ".$e->getTraceAsString();
    }
}


?>


您遇到了什么错误?您至少应该有足够的技能提供一个错误,而不是“哦,it jsut not workin,help”我不太确定错误是什么。我认为如果($client->getAccessToken())语句有问题,因为我可以看出它没有进入语句。所以我尝试删除它,看看是否可以生成错误,但没有打印错误。我不熟悉php和GoogleAPI,所以我尝试将代码示例放在一起,以便能够上传视频。