Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter-YouTube-API-Library Authenticating with registered account

I have added CodeIgniter-YouTube-API-Library for uploading video files to a registered youtube account.I have the apikey,oauth key,oauth secret in my hand.And I did the upload successfully .But the current problem is when another user trying to upload a video,instead of uploaded into the registered youtube account it goes to the current user's youtube account.How can I avoid this by prompting the user to login to the registered account.Please suggest a solution.I am using the following code.

public function request_youtube()
{
    $params['key'] = 'ENTER YOUR GOOGLE CONSUMER KEY';
    $params['secret'] = 'ENTER YOUR GOOGLE CONSUMER SECRET';
    $params['algorithm'] = 'HMAC-SHA1';

    $this->load->library('google_oauth', $params);
    $data = $this->google_oauth->get_request_token(site_url('example/access_youtube'));
    $this->session->set_userdata('token_secret', $data['token_secret']);
    redirect($data['redirect']); 
}

//This method will be redirected to automatically
//once the user approves access of your application
public function access_youtube()
{
    $params['key'] = 'ENTER YOUR GOOGLE CONSUMER KEY';
    $params['secret'] = 'ENTER YOUR GOOGLE CONSUMER SECRET';
    $params['algorithm'] = 'HMAC-SHA1';

    $this->load->library('google_oauth', $params);

    $oauth = $this->google_oauth->get_access_token(false, $this->session->userdata('token_secret'));

    $this->session->set_userdata('oauth_token', $oauth['oauth_token']);
    $this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
}

//This method can be called without having
//done the oauth steps
public function youtube_no_auth()
{
    $params['apikey'] = 'ENTER YOUR GOOGLE YOUTUBE API KEY';

    $this->load->library('youtube', $params);
    echo $this->youtube->getKeywordVideoFeed('pac man');
}


public function direct_upload()
{
    $videoPath = 'THE RELATIVE PATH ON YOUR SERVER TO THE VIDEO';
    $videoType = 'THE CONTENT TYPE OF THE VIDEO'; //This is the mime type of the video ex: 'video/3gpp'

    $params['apikey'] = 'ENTER YOUR GOOGLE YOUTUBE API KEY';
    $params['oauth']['key'] = 'ENTER YOUR GOOGLE CONSUMER KEY';
    $params['oauth']['secret'] = 'ENTER YOUR GOOGLE CONSUMER SECRET';
    $params['oauth']['algorithm'] = 'HMAC-SHA1';
    $params['oauth']['access_token'] = array('oauth_token'=>urlencode($this->session->userdata('oauth_token')),
                                             'oauth_token_secret'=>urlencode($this->session->userdata('oauth_token_secret')));
    $this->load->library('youtube', $params);

    $metadata = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><media:group><media:title type="plain">Test Direct Upload</media:title><media:description type="plain">Test Direct Uploading.</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:keywords>test</media:keywords></media:group></entry>';
    echo $this->youtube->directUpload($videoPath, $videoType, $metadata);
}
like image 834
Soojoo Avatar asked Nov 13 '22 15:11

Soojoo


1 Answers

In here https://developers.google.com/youtube/articles/codeigniter_library I can see that the directUpload function also has a user parameter. Try setting this to the id of the logged in user and see if this works.

like image 80
tix3 Avatar answered Nov 15 '22 05:11

tix3