消息和视频分享youtube php

时间:2014-01-20 11:18:03

标签: php youtube

我想获取用户的youtube收件箱并发送视频消息。下面是我用来检索收件箱的代码。收件箱来了显示用户XXXX的收件箱但收件箱为空,没有邮件到来。虽然我的收件箱中有四条视频消息。

$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&hellip;');
    } 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);

1 个答案:

答案 0 :(得分:0)

  

YouTube的视频回复功能已经停用,如中所述   这announcement。虽然现有视频回复仍然可用,   YouTube不再支持检索视频列表的功能   视频回复,上传新视频回复或删除   视频回复,但您可以删除在。中使用的视频   视频回复。因此,这些功能也不再存在   API支持。

https://developers.google.com/youtube/2.0/developers_guide_protocol_video_responses