PHP Google Drive API - Upload file to my own personal drive account
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 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 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
php oauth google-drive-sdk
asked Nov 20 at 2:33
NJ.
5,67411015
5,67411015
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 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 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12
add a comment |
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 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 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 at 3:02
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 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 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 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
It may help stackoverflow.com/questions/19335503/…
– Jared Chu
Nov 20 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 at 3:12
see stackoverflow.com/questions/19766912/…
– pinoyyid
Nov 24 at 3:12