1

I have a site that charges people for view the videos. I am trying use "google drive" as stream server for videos. I created a account service and the private key, and I am using the php library as you can see bellow:

define('ID_VIDEO', '0B9SXFdezvkZtOE9xVlVNR3U0a1U');

const CLIENT_ID = 'XXXXXXXXXXXXX.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'XXXXXXXXXXXXXX@developer.gserviceaccount.com';
const KEY_FILE = 'XXXXXXXXXXXXXXXXXXXXXX-privatekey.p12';

$client = new Google_Client();
$client->setApplicationName("JVideos");

session_start();
if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'),
$key)
);

$client->setClientId(CLIENT_ID);

$service = new Google_DriveService($client);
$file = $service->files->get(ID_VIDEO);
$access_toke = json_decode($client->getAccessToken(), TRUE);
$access_toke = $access_toke['access_token'];
?>
<embed width="100%" height="100%" name="plugin" src="<?= urldecode($file['embedLink']);?>&access_token=<?= $access_toke;?>" type="application/x-shockwave-flash" >

The problem is: how can I embed this video in my site without anybody do the login on google, the video should be viewed just with this authentication executed through of this api on the code above. When I execute this code, google return me that is necessary do the login.

Thanks

Emygdio
  • 63
  • 8

2 Answers2

0

If the file is share "Anyone with the link can view" or "Public can view" the code should be working fine.

The user's browser need to access the file to render the video, as your server have done to get the fileID.

I suggest the use of "Anyone with the link can view" permission so that videos don't show accidentally in search results.

smokybob
  • 663
  • 6
  • 13
  • Hi, The code works fine to bring the video, the problem is that the video can't be public, because there is charges to view them. And when this video is shown the google require the user do the login in a google account. The central ideia was use google as a private video server stream, to use in the online courses with no need the user has a google account. – Emygdio Jan 21 '14 at 11:51
0

The way that I have tried is not appropriate to site that don't want your video shown publicly, and don't want that the user has a google account to see the video too. The better way to this task is use the Google Cloud Storage rather than use Google Drive.

To accomplish this tasks first create a Cloud Storage account and generate .pem file, see on this link: https://developers.google.com/storage/docs/accesscontrol#Signed-URLs

After try this code on this link: https://stackoverflow.com/a/20817078/1018568

This approach worked very well for me.

Community
  • 1
  • 1
Emygdio
  • 63
  • 8