This repository was archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathexample.php
More file actions
executable file
·86 lines (71 loc) · 3.52 KB
/
example.php
File metadata and controls
executable file
·86 lines (71 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Example extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('url');
}
//CALL THIS METHOD FIRST BY GOING TO
//www.your_url.com/index.php/request_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');
}
//This method can be called after you executed
//the oauth steps
public function youtube_auth()
{
$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);
echo $this->youtube->getUserUploads();
}
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);
}
}
/* End of file example.php */
/* Location: ./application/controllers/example.php */