2

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

bitIO
  • 384
  • 3
  • 11
  • Are you sure the account has files? You can confirm using the OAuth playground code.google.com/oauthplayground – Ali Afshar Jul 30 '12 at 23:51
  • Sure. It has tons of files and folders. I'll have a look to the playground. Did not heard about it. – bitIO Jul 31 '12 at 02:18
  • Ok. I've made the request using the playground and works. So here is my question: what's wrong with the code I've using the service without OAuth since I'm using it as "Service Account"? – bitIO Jul 31 '12 at 07:59
  • @AliAfshar does Google Drive support ServiceAccounts? – bitIO Jul 31 '12 at 08:50

1 Answers1

0

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

Community
  • 1
  • 1
bitIO
  • 384
  • 3
  • 11