youtube php的消息和视频共享
我想获取用户的youtube收件箱并发送视频消息。下面是我用来检索收件箱的代码。inbox comes显示用户XXXX的收件箱,但收件箱为空,没有消息。我的收件箱里有四条视频信息youtube php的消息和视频共享,php,youtube,Php,Youtube,我想获取用户的youtube收件箱并发送视频消息。下面是我用来检索收件箱的代码。inbox comes显示用户XXXX的收件箱,但收件箱为空,没有消息。我的收件箱里有四条视频信息 $developer_key='REPLACE_ME'; $client_id= 'REPLACE_ME'; $client_secret='REPLACE_ME'; // error checking; user might have denied access if (isset($_GET['error']))
$developer_key='REPLACE_ME';
$client_id= 'REPLACE_ME';
$client_secret='REPLACE_ME';
// error checking; user might have denied access
if (isset($_GET['error'])) {
if ($_GET['error'] == 'access_denied') {
echo('You have denied access. Click <a href="'. $_SERVER["SCRIPT_NAME"] .'">here</a> to retry…');
} else {
echo("An error has occurred: ". $_GET['error']);
}
exit;
}
// Step 1: redirect to google account login if necessary
if(!isset($_GET['code']) || $_GET['code'] === '') {
Header('Location: https://accounts.google.com/o/oauth2/auth?client_id='. $client_id .
'&redirect_uri=http://localhost:8080/Test/sendMessage.php' .
'&scope=https://gdata.youtube.com&response_type=code&access_type=offline',
true, 307);
exit;
}
$authorization_code= $_GET['code'];
// Step 2: use authorization code to get access token
$url = "https://accounts.google.com/o/oauth2/token";
$message_post= 'code='. $authorization_code .
'&client_id='. $client_id .
'&client_secret='. $client_secret .
'&redirect_uri=http://localhost:8080/Test/sendMessage.php' .
'&grant_type=authorization_code';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo "<pre>";
echo "<br><br> message_post : ";
print_r($result);
if ($cur_error= curl_error($ch)) {
echo($cur_error);
curl_close($ch);
exit;
}
curl_close($ch);
$jsonArray= json_decode($result, true);
if ($jsonArray === null) {
echo("Could not decode JSON.");
exit;
}
if (isset($jsonArray['error'])) {
echo("An error has occurred: ". $jsonArray['error']);
exit;
}
if (!isset($jsonArray['access_token'])) {
echo("Access token not found.");
exit;
}
//The user's authentication token
$access_token= $jsonArray['access_token'];
$title ='krishna'; //The title of the caption track
$lang = 'en'; //The languageof the caption track
//$transcript = $_REQUEST['transcript']; //The caption file data
$inboxUrl ='https://gdata.youtube.com/feeds/api/users/default/inbox?alt=json&&key=AIzaSyBeh0Aevex7q3iRIY5bV3N9gx0WAkNBMi4&access_token=' . $access_token;
echo $inboxUrl . "<br />";
$homepage = file_get_contents($inboxUrl);
echo "file content : <pre>";
print_r($homepage);
$developer_key='REPLACE_ME';
$client_id='REPLACE_ME';
$client_secret='REPLACE_ME';
//错误检查;用户可能已拒绝访问
如果(isset($\u GET['error'])){
如果($\u GET['error']=='access\u denied'){
echo('您已拒绝访问。单击以重试&hellip;');
}否则{
echo(“发生错误:“.$\u GET['error']);
}
出口
}
//步骤1:必要时重定向到google帐户登录
如果(!isset($_GET['code']))|$_GET['code']=''{
标题('位置:https://accounts.google.com/o/oauth2/auth?client_id=“.$client_id。
“&重定向\u uri”=http://localhost:8080/Test/sendMessage.php' .
“&范围=https://gdata.youtube.com&response_type=code&access_type=offline',
对,307);
出口
}
$authorization\u code=$\u GET['code'];
//步骤2:使用授权码获取访问令牌
$url=”https://accounts.google.com/o/oauth2/token";
$message_post='code='$授权代码。
“&client_id=”$客户号。
“&client_secret=”$客户的秘密。
“&重定向\u uri”=http://localhost:8080/Test/sendMessage.php' .
“&grant_type=authorization_code”;
$ch=curl\u init($url);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$message_post);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result=curl\u exec($ch);
回声“;
回显“
信息_post:”;
打印(结果);
如果($cur\u error=curl\u error($ch)){
回声($cur_error);
卷曲关闭($ch);
出口
}
卷曲关闭($ch);
$jsonArray=json_decode($result,true);
if($jsonArray==null){
echo(“无法解码JSON”);
出口
}
如果(isset($jsonArray['error'])){
echo(“发生错误:“.jsonArray['error']);
出口
}
如果(!isset($jsonArray['access_token'])){
echo(“未找到访问令牌”);
出口
}
//用户的身份验证令牌
$access_token=$jsonArray['access_token'];
$title='krishna'//标题曲目的标题
$lang='en'//字幕音轨的语言
//$transcript=$_请求['transcript']//标题文件数据
$inboxUrl=https://gdata.youtube.com/feeds/api/users/default/inbox?alt=json&&key=AIzaSyBeh0Aevex7q3iRIY5bV3N9gx0WAkNBMi4&access_token=' . $接入令牌;
echo$inboxUrl。“
”;
$homepage=file\u get\u contents($inboxUrl);
echo“文件内容:”;
打印(主页);
YouTube的视频回复功能已经退役,如中所述
这虽然现有的视频响应仍然可用,
YouTube不再支持检索视频列表的功能
视频响应、上载新视频响应或删除
视频响应,但您可以删除在应用程序中使用的视频
视频响应。因此,这些功能也不再适用
API中支持
那么我们可以使用Data API版本3来实现这一点吗?。我也对V3进行了研究,但无法找到任何解决方案。不,它已被删除:(我想用户信息和视频共享…视频响应???请查看此链接我想使用此链接的功能