2013-06-11 3 views
1

안녕하세요 여러분, youtube.com에 자동 로그인하여 "브라우저 기반"의 비디오를 업로드하고 나중에 API를 통해 사이트에 표시 할 데이터를 얻으십시오. 그래서 기본적으로 여기에서 확장 프로그램을 다운로드했습니다. http://framework.zend.com/downloads/latest Zend Gdata. 그리고 그것을 작동하게하십시오.Zend Gdata Youtube 및 자동 로그인

잘 작동합니다 (데모 /.../YouTubeVideoApp). 하지만 확인 페이지 ("액세스 허용"\ "액세스 거부")없이 YouTube에 자동 로그인을 수행하려면 어떻게해야합니까? 현재 저는 개발자 키를 사용하여 YouTube API로 작업합니다.

확인의 메시지는 일반적으로

An anonymous application is requesting access to your Google Account for the product(s) listed below. 
    YouTube 
If you grant access, you can revoke access at any time under 'My Account'. The anonymous application will not have access to your password or any other personal information from your Google Account. Learn more 
This website has not registered with Google to establish a secure connection for authorization requests. We recommend that you continue the process only if you trust the following destination: 
    http://somedomain/operations.php 

내가 (API에 의해) YouTube에 연결을 생성하고 팝업 및 확인 페이지없이 (내 자신의 계정을 사용하여)이 동영상을 업로드해야 할 것입니다.

답변

1

내가 필요한 것은 액세스 토큰을 가져 와서 세션 값 "$ _SESSION [ 'sessionToken']"(으)로 설정하는 것입니다. javascript와 PHP를 함께 사용하면됩니다. 이전에 Picasa 웹 API를 사용하는 동안 항상 액세스 권한을 부여하거나 거부해야했지만 아래에 설명 된 변경 사항 이후에는 권한 부여 또는 액세스 페이지가 더 이상 필요하지 않습니다.

나는 젠드 Gdata는 YouTube에 통합되지 않은 있지만

자바 스크립트 팝업을 사용하여 로그인을하고, 필요한 범위에 대한 토큰을 얻을 사용하여 Picasa 웹 앨범을 통합했다. 아래는 자바 스크립트 코드입니다. picasa가 사용되는이 범위에서 범위를 YouTube 데이터로 변경하십시오.. 버튼을 클릭하여 "picasa"기능을 클릭하십시오. 여기

var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?'; 
var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='; 
var SCOPE  = 'https://picasaweb.google.com/data'; 
var CLIENTID = YOUR_CLIENT_ID; 
var REDIRECT = 'http://localhost/YOUR_REDIRECT_URL' 
var LOGOUT  = 'http://accounts.google.com/Logout'; 
var TYPE  = 'token'; 
var _url  = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE; 
var acToken; 
var tokenType; 
var expiresIn; 
var user; 
var loggedIn = false; 

function picasa() { 
    var win   = window.open(_url, "windowname1", 'width=800, height=600'); 

    var pollTimer = window.setInterval(function() { 
     console.log(win); 
     console.log(win.document); 
     console.log(win.document.URL); 
     if (win.document.URL.indexOf(REDIRECT) != -1) { 
      window.clearInterval(pollTimer); 
      var url = win.document.URL; 
      acToken = gup(url, 'access_token'); 
      tokenType = gup(url, 'token_type'); 
      expiresIn = gup(url, 'expires_in'); 
      win.close(); 

      validateToken(acToken); 
     } 
    }, 500); 
} 

function validateToken(token) { 
    $.ajax({ 
     url: VALIDURL + token, 
     data: null, 
     success: function(responseText){ 
      //alert(responseText.toSource()); 
      getPicasaAlbums(token); 
      loggedIn = true; 
     }, 
     dataType: "jsonp" 
    }); 
} 

function getPicasaAlbums(token) { 
    $.ajax({ 
    url: site_url+"ajaxs/getAlbums/picasa/"+token, 
    data: null, 
    success: function(response) { 
     alert("success"); 

    } 
}); 
} 

//credits: http://www.netlobo.com/url_query_string_javascript.html 
function gup(url, name) { 
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regexS = "[\\#&]"+name+"=([^&#]*)"; 
    var regex = new RegExp(regexS); 
    var results = regex.exec(url); 
    if(results == null) 
     return ""; 
    else 
     return results[1]; 
} 

나는 "getPicasaAlbums"기능에 아약스 호출을하고 거기에 $에 _SESSION에 토큰을 설정하고 그 뒤에 내가 젠드 쿼리를 사용하여 나열하는 앨범을 얻을 수 있어요입니다. 여기에 "getPicasaAlbums"함수에서 ajax를 사용하여 호출하는 php 파일의 코드가 있습니다.

function getAlbums($imported_from = '',$token = '') { 
    //echo $imported_from; //picasa 
    //echo $token; 

    $_SESSION['sessionToken'] = $token;// set sessionToken 
      $client = getAuthSubHttpClient(); 
      $user = "default"; 

      $photos = new Zend_Gdata_Photos($client); 
      $query = new Zend_Gdata_Photos_UserQuery(); 
      $query->setUser($user); 

      $userFeed = $photos->getUserFeed(null, $query); 

echo "<pre>";print_r($userFeed);echo "</pre>";exit; 
} 

나는 이것이 당신에게 약간의 도움이 될 것이라고 생각합니다. 위의 "getAlbums"함수의 코드를 youtube의 zend 데이터 코드로 다시 매핑하여 데이터를 검색하십시오.

좋은 예에게 로그인 팝업의 & referene 여기

http://www.gethugames.in/blog/2012/04/authentication-and-authorization-for-google-apis-in-javascript-popup-window-tutorial.html

입니다