2014-01-20 58 views
0

我想要得到的YouTube用户的收件箱和发送视频消息话题。下面是我用来检索收件箱的代码。收件箱来显示用户XXXX收件箱但收件箱是空的,没有消息。而我的收件箱里有四条视频信息。消息和视频共享YouTube的PHP

$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); 

回答

0

YouTube的视频回复功能,如 这announcement解释已经退役。虽然现有的视频响应仍然可用, 的YouTube不再支持检索的视频 回复列表的视频,上传新视频回复,或者删除 视频回复,但你可以删除在使用视频的能力一个 视频回应。因此,这些功能也不再支持API中的 。

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

+0

所以我们可以做到这一点使用数据API第3版?我也研究过V3,但无法得到任何解决方案。 – user2995370

+0

NOP,它被明确删除:( –

+0

我想用户信息和视频共享......视频响应???请访问以下链接https://developers.google.com/youtube/2.0/developers_guide_protocol_messages?hl=en# Retrieving_messages我想使用这个链接的功能 – user2995370