download Google Drive files through Google Drive API
I have make the server account authentication through the python code:
APP_CREDENTIALS = service_account.Credentials.from_service_account_file(
#config.EE_ACCOUNT,
config.EE_PRIVATE_KEY_FILE,
scopes = OAUTH_SCOPE)
service = build('drive', 'v3', credentials=APP_CREDENTIALS)
And I typed this code to print those files in drive:
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
logging.info('Task succeeded (id: %s).', task.id)
results = service.files().list().execute()
items = results.get('files', )
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
if item['id'] == '1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF':
print('downloadfiles')
download_file(item['id'], service)
print(u'{0} ({1})'.format(item['name'], item['id']))
The result was:
NDVI_1229.tif (1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF)
NDVI_1229.tif (1y5anN0zpRYW180pd0t74xbOWxr0bjfdm)
NDVI_1229.tif (1X8fYAzRrUBxPMLpZmx_bJULLwq09lJPb)
NDVI_1229.tif (1iSk51dCTAyiVjPbCFQ3irnjhYsn708mV)
NDVI_1229.tif (1Cr3G7tZF2xYAmO70n6tvSs65Ot7MWr69)
NDVI_1229.tif (1KlGUVmr3maaiya4WAeD0ShI6DAsUcxT5)
NDVI_1229.tif (1kkGxRQulWYIG7tX0J8f_n5T1hwhYK_O0)
NDVI_1229.tif (1AqgchB8X7aul1rhVk76GlF1Iwm5N-UFR)
NDVI_1229.tif (14A7Kzcweaft8eBof_nWQGtLQ5RwvpFlP)
NDVI.tif (1GvY3JlMmqE-TgvqR5Fg8zPa9JvuJAyHJ)
NDVI.tif (15N4Kge7gR5bk7B3ZwRBG4Tad0PKU9nPc)
NDVI.tif (19cr8Ena_oztorgmOQL-FTBvNq4vN7nD9)
NDVI.tif (1oK5N5GTiTthkpk6rtjFF9wM4qeXDtESR)
Now I want to download those files, and I use the method given in the Google Drive API official website. The code was shown below:
def download_file(file_id, drive_service):
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = http.MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
return fh.getvalue()
And I got this answer:
INFO 2019-01-02 08:32:04,585 discovery.py:871] URL being requested: GET https://www.googleapis.com/drive/v3/files/1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF?alt=media
Download 100%.
I opened the link, its content was like this:
{
"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."
}
}
So I am confused that whether my authentication method is correct or not.
And I have tried different ways to download files from this drive or export this drive's files to other user's drive, it has the same answer.
google-drive-sdk
add a comment |
I have make the server account authentication through the python code:
APP_CREDENTIALS = service_account.Credentials.from_service_account_file(
#config.EE_ACCOUNT,
config.EE_PRIVATE_KEY_FILE,
scopes = OAUTH_SCOPE)
service = build('drive', 'v3', credentials=APP_CREDENTIALS)
And I typed this code to print those files in drive:
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
logging.info('Task succeeded (id: %s).', task.id)
results = service.files().list().execute()
items = results.get('files', )
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
if item['id'] == '1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF':
print('downloadfiles')
download_file(item['id'], service)
print(u'{0} ({1})'.format(item['name'], item['id']))
The result was:
NDVI_1229.tif (1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF)
NDVI_1229.tif (1y5anN0zpRYW180pd0t74xbOWxr0bjfdm)
NDVI_1229.tif (1X8fYAzRrUBxPMLpZmx_bJULLwq09lJPb)
NDVI_1229.tif (1iSk51dCTAyiVjPbCFQ3irnjhYsn708mV)
NDVI_1229.tif (1Cr3G7tZF2xYAmO70n6tvSs65Ot7MWr69)
NDVI_1229.tif (1KlGUVmr3maaiya4WAeD0ShI6DAsUcxT5)
NDVI_1229.tif (1kkGxRQulWYIG7tX0J8f_n5T1hwhYK_O0)
NDVI_1229.tif (1AqgchB8X7aul1rhVk76GlF1Iwm5N-UFR)
NDVI_1229.tif (14A7Kzcweaft8eBof_nWQGtLQ5RwvpFlP)
NDVI.tif (1GvY3JlMmqE-TgvqR5Fg8zPa9JvuJAyHJ)
NDVI.tif (15N4Kge7gR5bk7B3ZwRBG4Tad0PKU9nPc)
NDVI.tif (19cr8Ena_oztorgmOQL-FTBvNq4vN7nD9)
NDVI.tif (1oK5N5GTiTthkpk6rtjFF9wM4qeXDtESR)
Now I want to download those files, and I use the method given in the Google Drive API official website. The code was shown below:
def download_file(file_id, drive_service):
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = http.MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
return fh.getvalue()
And I got this answer:
INFO 2019-01-02 08:32:04,585 discovery.py:871] URL being requested: GET https://www.googleapis.com/drive/v3/files/1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF?alt=media
Download 100%.
I opened the link, its content was like this:
{
"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."
}
}
So I am confused that whether my authentication method is correct or not.
And I have tried different ways to download files from this drive or export this drive's files to other user's drive, it has the same answer.
google-drive-sdk
add a comment |
I have make the server account authentication through the python code:
APP_CREDENTIALS = service_account.Credentials.from_service_account_file(
#config.EE_ACCOUNT,
config.EE_PRIVATE_KEY_FILE,
scopes = OAUTH_SCOPE)
service = build('drive', 'v3', credentials=APP_CREDENTIALS)
And I typed this code to print those files in drive:
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
logging.info('Task succeeded (id: %s).', task.id)
results = service.files().list().execute()
items = results.get('files', )
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
if item['id'] == '1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF':
print('downloadfiles')
download_file(item['id'], service)
print(u'{0} ({1})'.format(item['name'], item['id']))
The result was:
NDVI_1229.tif (1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF)
NDVI_1229.tif (1y5anN0zpRYW180pd0t74xbOWxr0bjfdm)
NDVI_1229.tif (1X8fYAzRrUBxPMLpZmx_bJULLwq09lJPb)
NDVI_1229.tif (1iSk51dCTAyiVjPbCFQ3irnjhYsn708mV)
NDVI_1229.tif (1Cr3G7tZF2xYAmO70n6tvSs65Ot7MWr69)
NDVI_1229.tif (1KlGUVmr3maaiya4WAeD0ShI6DAsUcxT5)
NDVI_1229.tif (1kkGxRQulWYIG7tX0J8f_n5T1hwhYK_O0)
NDVI_1229.tif (1AqgchB8X7aul1rhVk76GlF1Iwm5N-UFR)
NDVI_1229.tif (14A7Kzcweaft8eBof_nWQGtLQ5RwvpFlP)
NDVI.tif (1GvY3JlMmqE-TgvqR5Fg8zPa9JvuJAyHJ)
NDVI.tif (15N4Kge7gR5bk7B3ZwRBG4Tad0PKU9nPc)
NDVI.tif (19cr8Ena_oztorgmOQL-FTBvNq4vN7nD9)
NDVI.tif (1oK5N5GTiTthkpk6rtjFF9wM4qeXDtESR)
Now I want to download those files, and I use the method given in the Google Drive API official website. The code was shown below:
def download_file(file_id, drive_service):
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = http.MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
return fh.getvalue()
And I got this answer:
INFO 2019-01-02 08:32:04,585 discovery.py:871] URL being requested: GET https://www.googleapis.com/drive/v3/files/1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF?alt=media
Download 100%.
I opened the link, its content was like this:
{
"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."
}
}
So I am confused that whether my authentication method is correct or not.
And I have tried different ways to download files from this drive or export this drive's files to other user's drive, it has the same answer.
google-drive-sdk
I have make the server account authentication through the python code:
APP_CREDENTIALS = service_account.Credentials.from_service_account_file(
#config.EE_ACCOUNT,
config.EE_PRIVATE_KEY_FILE,
scopes = OAUTH_SCOPE)
service = build('drive', 'v3', credentials=APP_CREDENTIALS)
And I typed this code to print those files in drive:
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
logging.info('Task succeeded (id: %s).', task.id)
results = service.files().list().execute()
items = results.get('files', )
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
if item['id'] == '1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF':
print('downloadfiles')
download_file(item['id'], service)
print(u'{0} ({1})'.format(item['name'], item['id']))
The result was:
NDVI_1229.tif (1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF)
NDVI_1229.tif (1y5anN0zpRYW180pd0t74xbOWxr0bjfdm)
NDVI_1229.tif (1X8fYAzRrUBxPMLpZmx_bJULLwq09lJPb)
NDVI_1229.tif (1iSk51dCTAyiVjPbCFQ3irnjhYsn708mV)
NDVI_1229.tif (1Cr3G7tZF2xYAmO70n6tvSs65Ot7MWr69)
NDVI_1229.tif (1KlGUVmr3maaiya4WAeD0ShI6DAsUcxT5)
NDVI_1229.tif (1kkGxRQulWYIG7tX0J8f_n5T1hwhYK_O0)
NDVI_1229.tif (1AqgchB8X7aul1rhVk76GlF1Iwm5N-UFR)
NDVI_1229.tif (14A7Kzcweaft8eBof_nWQGtLQ5RwvpFlP)
NDVI.tif (1GvY3JlMmqE-TgvqR5Fg8zPa9JvuJAyHJ)
NDVI.tif (15N4Kge7gR5bk7B3ZwRBG4Tad0PKU9nPc)
NDVI.tif (19cr8Ena_oztorgmOQL-FTBvNq4vN7nD9)
NDVI.tif (1oK5N5GTiTthkpk6rtjFF9wM4qeXDtESR)
Now I want to download those files, and I use the method given in the Google Drive API official website. The code was shown below:
def download_file(file_id, drive_service):
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = http.MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
return fh.getvalue()
And I got this answer:
INFO 2019-01-02 08:32:04,585 discovery.py:871] URL being requested: GET https://www.googleapis.com/drive/v3/files/1MiXjaHXU3ktOrkVwdkAABuNM-HXhJGGF?alt=media
Download 100%.
I opened the link, its content was like this:
{
"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."
}
}
So I am confused that whether my authentication method is correct or not.
And I have tried different ways to download files from this drive or export this drive's files to other user's drive, it has the same answer.
google-drive-sdk
google-drive-sdk
edited Jan 4 at 1:10
rilla
342114
342114
asked Jan 3 at 1:09
zi yangzi yang
11
11
add a comment |
add a comment |
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
});
}
});
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%2f54015143%2fdownload-google-drive-files-through-google-drive-api%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
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.
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%2f54015143%2fdownload-google-drive-files-through-google-drive-api%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
