1

こんにちは、youtube.com への自動ログインで「ブラウザベース」の動画をアップロードするのに助けが必要です (後で API によってサイトに表示するデータを取得します)。基本的に、ここから拡張機能をダウンロードしましたhttp://framework.zend.com/downloads/latest Zend Gdata 。そして、それを機能させます。

正常に動作します (demos/.../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

一般に、YouTube への接続を (API によって) 作成し、そこに (自分のアカウントを使用して) ポップアップや確認ページなしでビデオをアップロードする必要があります。

4

1 に答える 1

1

必要なのは、アクセストークンを取得して、セッション値「$_SESSION['sessionToken']」に設定することだけだと思います。これを行うには、javascript と PHP を組み合わせる必要があります。以前は、Picasa Web API を使用している間は常にアクセスを許可または拒否する必要がありましたが、以下で説明する変更後、許可またはアクセス ページは不要になりました。

YouTube を zend Gdata と統合していませんが、それを使用して Picasa ウェブ アルバムを統合しています。

JavaScript ポップアップを使用してログインし、必要なスコープのトークンを取得します。以下はJavaScriptコードです。このスコープでは picasa が使用されているため、スコープを youtube データに変更します。. ボタンonclickの機能「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」で ajax 呼び出しを行い、そこにトークンを $_session に設定しています。その後、zend クエリを使用してアルバム リストを取得できます。これは、関数「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 データ コードに置き換えて、データを取得します。

ログインポップアップの良い例とレフェレンはこちら

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

于 2013-06-22T06:32:57.247 に答える