【发布时间】:2018-02-14 14:52:14
【问题描述】:
我正在使用此页面中的代码 https://developers.google.com/youtube/v3/code_samples/php#upload_a_video 将视频上传到 youtube。但我无法将上传的视频放到一个已经存在的播放列表中。
我发现这个类 Google_Service_YouTube_Resource_PlaylistItems 有 insert 方法,但我不知道如何使用它
这是我想出来的
$resourceId = new \Google_Service_YouTube_ResourceId();
$resourceId->setVideoId( $status["id"] );
$resourceId->setKind('youtube#video');
$playlistItemSnippet = new \Google_Service_YouTube_PlaylistItemSnippet();
$playlistItemSnippet->setTitle('First video in the test playlist');
$playlistItemSnippet->setPlaylistId($playlistId);
$playlistItemSnippet->setResourceId($resourceId);
$playlistItem = new \Google_Service_YouTube_PlaylistItem();
$playlistItem->setSnippet($playlistItemSnippet);
$playlistItemResponse = $youtube->playlistItems->insert(
'snippet,contentDetails', $playlistItem, array());
这是回复
object(GuzzleHttp\Psr7\Request)#698 (7) {
["method":"GuzzleHttp\Psr7\Request":private]=>
string(4) "POST"
["requestTarget":"GuzzleHttp\Psr7\Request":private]=>
NULL
["uri":"GuzzleHttp\Psr7\Request":private]=>
object(GuzzleHttp\Psr7\Uri)#749 (7) {
["scheme":"GuzzleHttp\Psr7\Uri":private]=>
string(5) "https"
["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
string(0) ""
["host":"GuzzleHttp\Psr7\Uri":private]=>
string(18) "www.googleapis.com"
["port":"GuzzleHttp\Psr7\Uri":private]=>
NULL
["path":"GuzzleHttp\Psr7\Uri":private]=>
string(25) "/youtube/v3/playlistItems"
["query":"GuzzleHttp\Psr7\Uri":private]=>
string(29) "part=snippet%2CcontentDetails"
["fragment":"GuzzleHttp\Psr7\Uri":private]=>
string(0) ""
}
["headers":"GuzzleHttp\Psr7\Request":private]=>
array(3) {
["Host"]=>
array(1) {
[0]=>
string(18) "www.googleapis.com"
}
["content-type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["X-Php-Expected-Class"]=>
array(1) {
[0]=>
string(35) "Google_Service_YouTube_PlaylistItem"
}
}
["headerNames":"GuzzleHttp\Psr7\Request":private]=>
array(3) {
["content-type"]=>
string(12) "content-type"
["host"]=>
string(4) "Host"
["x-php-expected-class"]=>
string(20) "X-Php-Expected-Class"
}
["protocol":"GuzzleHttp\Psr7\Request":private]=>
string(3) "1.1"
["stream":"GuzzleHttp\Psr7\Request":private]=>
object(GuzzleHttp\Psr7\Stream)#730 (7) {
["stream":"GuzzleHttp\Psr7\Stream":private]=>
resource(589) of type (stream)
["size":"GuzzleHttp\Psr7\Stream":private]=>
NULL
["seekable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["readable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["writable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["uri":"GuzzleHttp\Psr7\Stream":private]=>
string(10) "php://temp"
["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
array(0) {
}
}
}
注意: 我可以通过 API 上传视频,因此身份验证和连接以及所有基本要求都可以
【问题讨论】:
标签: youtube google-api youtube-api youtube-data-api google-api-php-client