Google Drive PHP API V2 No results when listing

By : bitIO
Source: Stackoverflow.com
Question!

I'm creating a module for joomla that lists the the contents of a given folder. This module works as a service, so no OAuth should be required. I'm stuck since every request I make has the same answer, no items. So I would like to know if I'm creating the client/service in a wrong way or I may have registered the application in a wrong way. Here is the code:

// this class is where I have all the IDs from the google console
require_once(dirname(__FILE__) . '/gdrive/config.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/apiClient.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/contrib/apiDriveService.php');

$client = new apiClient();
$key    = file_get_contents(Config::KEY_FILE);
$client->setClientId(Config::CLIENT_ID);

$client->setUseObjects(true);
$client->setAssertionCredentials(new apiAssertionCredentials(
    Config::SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/drive'), $key)
);

$service = new apiDriveService($client);

try {
    $parameters = array();
    $parameters['maxResults'] = $maxResults;

    $files = $service->files->listFiles($parameters);

    $items = $files->getItems();
    var_dump($items);
    $pageToken = $files->getNextPageToken();
} catch (apiServiceException $e) {
    print "Error code :" . $e->getCode() . "\n";
    // Error message is formatted as "Error calling <REQUEST METHOD> <REQUEST URL>: (<CODE>) <MESSAGE OR REASON>".
    print "Error message: " . $e->getMessage() . "\n";    
} catch (apiException $e) {
    // Other error.
    print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "\n";
} catch (Exception $e) {
    print "Cannot retrieve the files";
    print($e->getMessage());
}

Sorry to ask such a noob question but this is driving me crazy Thanks

P.S. just for the record, I followed this google-api-php-client/wiki/OAuth2#Service_Accounts

By : bitIO


Answers

After having a second look to the documentation I found that Google Drive does not support service accounts. I don't know if this is going to change but, with the requirements I have (I need to show in the web is what an end user uploads to a folder (which is public) using the desktop app) I think I cannot use google drive as a valid solution.

I found a solution but I don't like to much since I should have to refresh the token forever Google Drive SDK Service Account Error

By : bitIO


This video can help you solving your question :)
By: admin