5

我已经添加了 CodeIgniter-YouTube-API-Library 用于将视频文件上传到已注册的 youtube 帐户。我手上有 apikey、oauth 密钥、oauth 密钥。我成功上传了。但是当前的问题是当另一个用户尝试上传视频时,而不是上传到注册的 youtube 帐户,而是转到当前用户的 youtube 帐户。如何通过提示用户登录到注册帐户来避免这种情况。请建议一个解决方案。我正在使用以下代码。

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

1 回答 1

1

在这里https://developers.google.com/youtube/articles/codeigniter_library我可以看到 directUpload 函数也有一个用户参数。尝试将其设置为登录用户的 id 并查看是否有效。

于 2013-02-20T20:09:50.457 回答