PHP Google Drive API - Upload file to my own personal drive account












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?










share|improve this question























  • It may help stackoverflow.com/questions/19335503/…

    – Jared Chu
    Nov 20 '18 at 3: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 3:12











  • see stackoverflow.com/questions/19766912/…

    – pinoyyid
    Nov 24 '18 at 3:12
















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?










share|improve this question























  • It may help stackoverflow.com/questions/19335503/…

    – Jared Chu
    Nov 20 '18 at 3: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 3:12











  • see stackoverflow.com/questions/19766912/…

    – pinoyyid
    Nov 24 '18 at 3:12














0












0








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?










share|improve this question














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?







php oauth google-drive-sdk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 2:33









NJ.NJ.

5,76911215




5,76911215













  • It may help stackoverflow.com/questions/19335503/…

    – Jared Chu
    Nov 20 '18 at 3: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 3:12











  • see stackoverflow.com/questions/19766912/…

    – pinoyyid
    Nov 24 '18 at 3:12



















  • It may help stackoverflow.com/questions/19335503/…

    – Jared Chu
    Nov 20 '18 at 3: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 3:12











  • see stackoverflow.com/questions/19766912/…

    – pinoyyid
    Nov 24 '18 at 3:12

















It may help stackoverflow.com/questions/19335503/…

– Jared Chu
Nov 20 '18 at 3:02





It may help stackoverflow.com/questions/19335503/…

– Jared Chu
Nov 20 '18 at 3:02




1




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 3:12





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 3:12













see stackoverflow.com/questions/19766912/…

– pinoyyid
Nov 24 '18 at 3:12





see stackoverflow.com/questions/19766912/…

– pinoyyid
Nov 24 '18 at 3:12












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385387%2fphp-google-drive-api-upload-file-to-my-own-personal-drive-account%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385387%2fphp-google-drive-api-upload-file-to-my-own-personal-drive-account%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?