2013-04-30 4 views
0

YouTube 사용자에게 메시지를 보내기위한 스크립트를 개발 중입니다. 사실, 해당 저자의 정보 (YouTube 동영상 ID, 저자 이름, 세부 정보 등)가 포함 된 YouTube 데이터 피드가 있습니다. YouTube API를 사용하여 메시지를 보내야합니다. 이것이 가능한가?YouTube API를 사용하여 youtube 사용자에게 메시지를 보내는 방법은 무엇입니까?

Oauth 로그인 및 YouTube API 피드를 작성하여 해당 비디오에 대한 비디오 및 사용자 정보를 얻었습니다. YouTube API의이 설명서 (https://developers.google.com/youtube/2.0/developers_guide_protocol_messages#Sending_a_message)를 보내지 만 메시지를 보낼 수있는 옵션이 없습니다. 해당 비디오 작성자의받은 편지함에 새 메일 대신 설명으로 메시지를 보내는 옵션 만 있습니다.

알고 계시면 알려 주시기 바랍니다. 아래 스크립트를 붙여 넣었습니다.

$developer_key='###########################'; 
    $client_id=  '#################'; 
    $client_secret='#################'; 

    // 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%3A%2F%2Flocalhost%2Ftest%2Foauth_1.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/test/oauth_1.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); 

    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 
    $ur='https://gdata.youtube.com/feeds/api/users/recepient_username/inbox'; 



    $headers = array(

     'Host: gdata.youtube.com', 
     'Content-Type: application/atom+xml utf-8', 
     'Content-Language: ' . $lang, 
     'Slug: ' . rawurlencode($title), 
     'Authorization: AuthSub token=' . $access_token, 
     'GData-Version: 2', 
     'X-GData-Key: key=' . $developer_key 
    ); 


    $xml = '&xml=<?xml version="1.0" encoding="UTF-8"?> 
    <entry xmlns="http://www.w3.org/2005/Atom" 
     xmlns:yt="http://gdata.youtube.com/schemas/2007"> 
     <id>cSVSeHFKBjU</id> 
     <summary>sending a message from the api</summary> 
    </entry>'; 
    // create a new cURL resource 
    $ch = curl_init(); 

    // set URL and other appropriate options 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HEADER, TRUE); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($xml)); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 

    $tt = curl_getinfo($ch); 
    print_r($tt); 


    $result = curl_exec($ch); 
    print_r($result); 


    // close cURL resource, and free up system resources 
    curl_close($ch); 

echo "DONE! Token:" . $access_token . "<br />\n"; 
var_dump($result); 

그래서 댓글 대신 동영상 사용자에게 메일을 보낼 수있는 옵션이 있는지 확인하고 업데이트 해주세요.

답변

0

YouTube v2.0 API는 사용자의받은 편지함으로 새 메시지를 보낼 수 있지만 메시지에는 해당 동영상에 대한 동영상 및 댓글이 모두 포함되어야합니다. 문자 메시지 만 보낼 수는 없습니다.

YouTube의 메시징 지원을 사용하는 방법을 설명하는 사용 사례가 포함 된 설명서는 here입니다.

관련 문제