Get image URL instead of content from google drive api

Viewed 4309

Trying to get image URL instead of file content from Google Drive API. In the new version this GOOD thing is deprecated.

I searched a lot, on Google developer class there is a method, but its missing in the new version as well.

The problem is that I'm going to get lot of images from the Drive, but don't want to loose the speed of Google trying to path trough my app all images. And this is stupid also.

Is there a way to get those link somehow still?

This is my code I use to get file content:

$this->client = new \Google_Client();
$this->client->setAuthConfigFile('config.json');
$this->client->setScopes('https://www.googleapis.com/auth/drive');


if (isset($_GET['code'])) $code = $_GET['code'];

if(!isset($_SESSION['access_token'])){
    if (!isset( $code )){
        $auth_url = $this->client->createAuthUrl();
        $filtered_url = filter_var($auth_url, FILTER_SANITIZE_URL);
        return redirect($filtered_url);
    }else{
        $this->client->authenticate($_GET['code']);
        $_SESSION['access_token'] = $this->client->getAccessToken();
        // return redirect('/');
    }
}

$this->service = new \Google_Service_Drive($this->client);
$file_id = '0B3vR4cBcxn4oNm9TSlBzcngyMzQ';
$results = $this->service->files->get($file_id, array('alt' => 'media'));

$imaga = $results->getBody()->getContents();

$imageData = base64_encode($imaga);
$contentType = $results->getHeader("content-type");

$src = 'data: '.$contentType[0].';base64,'.$imageData;
2 Answers
Related