Question

Hello guys I need help in auto login to youtube.com to upload videos "browser-based" (and later get them data to show in a site by api). So basicly I downloaded extension from here http://framework.zend.com/downloads/latest Zend Gdata. And make it work.

It works fine (demos/.../YouTubeVideoApp). But how can i do auto login to youtube without confirmation page ("grant access" \ "deny access")? Currently I use developer key to work with youtube api.

The message of confirmation is

 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

In general I need create connection to youtube (by api) and upload there (using my own account) video without any popups and confirmation pages.

Was it helpful?

Solution

i think all you need is to get a access token and set it to a session value "$_SESSION['sessionToken']". Combination of javascript and PHP will need to do this. previously i always have to grant access or deny it while using Picasa web API but after changes that i described below, grant or access page is no longer needed.

I have not integrated youtube with zend Gdata but have integrated Picasa web Albums using it

make a login using javascript popup and get a token for a needed scope. below is a javascript code. change your scope to youtube data as in this scope for picasa is used.. click function "picasa" on your button onclick.

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];
}

Here i am making a ajax call in function "getPicasaAlbums" and setting token to a $_session there and after it i am able to get a album listing using zend queries. here is a some code of php file that i am calling using ajax in function "getPicasaAlbums".

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;
}

i think this will help you a little in your task. relpace above "getAlbums" function's code with your youtube zend data code to retrieve data.

good example & referene of a login popup is here

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top