0

I am trying to build a very simplified piece of code that is to simply upload a local file from server to my personal drive account. Right now I am struggling with authentication issues, and not sure what kind of credential type I need.

Importantly, since this is only accessing my own private drive, I want to upload my credentials once and not have it ask in future. I am not trying to use oAuth to access my user's drives at all. It seems most documentation is for if we are trying to authenticate and access OTHER users drives?

I think I can manage the upload code once I can authenticate, but right now I can't even list my existing files.

Here is my code so far:

<?php
require_once 'google-api-php-client/vendor/autoload.php';

/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient($credentialsPath = ''){
    $client = new Google_Client();
    $client->setApplicationName('Google Drive API');
    $client->setAuthConfig($credentialsPath); // saved some credentials from console, but not sure which ones to use? 
    $client->setScopes(Google_Service_Drive::DRIVE);

    return $client;
}


// Get the API client and construct the service object.
$client = getClient($credentialsPath);
$service = new Google_Service_Drive($client);

// Print the names and IDs for up to 10 files.
$optParams = array(
  'pageSize' => 10,
  'fields' => 'nextPageToken, files(id, name)'
);
$results = $service->files->listFiles($optParams);

if (count($results->getFiles()) == 0) {
    print "No files found.\n";
} else {
    print "Files:\n";
    foreach ($results->getFiles() as $file) {
        printf("%s (%s)\n", $file->getName(), $file->getId());
    }
}

When I run this code I get the following error code:

Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "usageLimits", "reason": "dailyLimitExceededUnreg", "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "extendedHelp": "https://code.google.com/apis/console" } ], "code": 403, "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." }

The few things I looked at suggest this code is not about daily limit, but in fact incorrect usage of credentials. Any idea how I can fix this?

NJ.
  • 7,486
  • 1
  • 19
  • 20
  • It may help https://stackoverflow.com/questions/19335503/keep-getting-a-daily-limit-for-unauthenticated-use-exceeded-continued-use-requ – Jared Chu Nov 20 '18 at 03:02
  • 1
    Thanks for letting me know, I had a look and tried various answers there. It doesn't seem to help at all. I even created a new project entirely and a fresh OAuth 2.0 credential which I downloaded as JSON and reference in my PHP file there. Still no luck, with same issue I am receiving. – NJ. Nov 20 '18 at 03:12
  • see https://stackoverflow.com/questions/19766912/how-do-i-authorise-an-app-web-or-installed-without-user-intervention – pinoyyid Nov 24 '18 at 03:12

0 Answers0