The readme is here.
robinbobin / react-native-google-drive-api-wrapper Goto Github PK
View Code? Open in Web Editor NEWThis wrapper facilitates the use of the Google Drive API in React Native projects.
This wrapper facilitates the use of the Google Drive API in React Native projects.
The readme is here.
Hi everybody.
i did see some issues and in google search how download file.
i did see this method: gdrive.files.download(...)
but, this function returns TypeError: undefined is not a function (near '...gdrive.files.download...')]
does this function download still exist? or is there another equivalent function to download?
thanks
I can get fileId using getId()
function, but cannot get contents of file.
Download file is necessary?
Here is my code.
if (GDrive.isInitialized()) {
try {
let fileId = await GDrive.files.getId('File', ['root'], 'text/plain')
let content = await GDrive.files.get(fileId)
} catch(e) {
console.log(e)
}
}
By the way, Upload with GDrive is working.
I'm trying to list all my drive files and get the following error:
"error": Object {
"code": 403,
"errors": Array [
Object {
"domain": "global",
"message": "Insufficient Permission: Request had insufficient authentication scopes.",
"reason": "insufficientPermissions",
},
],
"message": "Insufficient Permission: Request had insufficient authentication scopes.",
},
}
My code:
GDrive.files
.list({
q: "'root' in parents",
fields: '*',
corpora: 'drive',
supportsAllDrives: true,
includeItemsFromAllDrives: true,
driveId: 'xxxxxxxxxxxxxxx',
})
.then((res) => res.json())
.then((data) => console.log('data.files', data))
.catch((err) => console.log(err));
How to assign these permissions?
I saw that it needs to link a library, but expo doesn't allow that. Is there any way to use it without having to export?
I recently started using this library & i love this wrapper library for react native.
I am able to upload a file but not able to create a folder & generate shareable link for the uploaded file.
Can you please help me with that. It would be great if you can give some more examples in readme.md
Hi there!
I have been using this library for a couple of months now and it worked GREAT! Recently, some users have reported that the backup feature of my app stopped working and I just confirmed this, and I can’t find the source of the issue.
I have an upload/download-app-data functions (posted below) and it seems that both are not working correctly.
The createNewGoogleDriveBackup
function DOES create a folder and it appears that GDrive.files.createFileMultipart
successfully finishes (aka uploads the file) but when I go to my Drive I can only see that the folder was created but it is empty.
When I try to download the file it is unable to find the file within.
Any hints would be greatly appreciated!
This code worked untouched for the past 5 months or so, and I haven’t touched it since.
EDIT: After a bit of digging I see that GDrive.files.createFileMultipart
is resolving with status 403
(Forbidden). So I am allowed to create a folder but not allowed to upload a file, which I find strange.
When I log in with Google I specifically request permission in the scopes as seen below:
GoogleSignin.configure({
scopes: ['https://www.googleapis.com/auth/drive.file'], // what API you want to access on behalf of the user
webClientId: '...', // client ID of type WEB for your server (needed to verify user ID and offline access)
offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
forceConsentPrompt: false, // [Android] if you want to show the authorization prompt at each login.
});
const BACKUP_FOLDER_NAME = 'Moodflow';
const BACKUP_FILE_NAME = 'moodflow_backup.json';
export const createNewGoogleDriveBackup = (shouldUpdateRequestMetadata = false) => {
return async dispatch => {
const appState = store.getState()
shouldUpdateRequestMetadata ? dispatch({ type: START_REQUEST }) : null;
try {
await GoogleSignin.signInSilently()
const token = await GoogleSignin.getTokens();
GDrive.setAccessToken(token.accessToken);
GDrive.init();
// Gets the id of the first folder with the specified name and parents, creating the folder if it doesn't exist.
const folderId = await GDrive.files.safeCreateFolder({ name: BACKUP_FOLDER_NAME, parents: ["root"] });
console.log('folderId', folderId)
// Gets the id of the first file with the specified metadata.
const fileId = await GDrive.files.getId(BACKUP_FILE_NAME, ['root', folderId], "application/json", false);
console.log('fileId', fileId)
if (typeof fileId !== 'undefined') {
await GDrive.files.delete(fileId);
}
// modify app state to include only relevant data
const { challenges, moods, userInfo, routines, activities, gratitudeJournal } = appState;
const appStateToUpload = {
moods,
routines,
userInfo,
activities,
challenges,
gratitudeJournal,
};
const uploadPayload = JSON.stringify(appStateToUpload)
console.log('uploadPayload', typeof uploadPayload, uploadPayload)
await GDrive.files.createFileMultipart(
uploadPayload,
"application/json",
{ parents: ['root', folderId], name: BACKUP_FILE_NAME },
false,
);
console.log('Uploaded backup!')
shouldUpdateRequestMetadata ? dispatch({ type: REQUEST_SUCCESSFUL }) : null
return dispatch({ type: UPDATE_BACKUP_TIMESTAMP });
} catch (error) {
console.log('Error creating backup: ', error)
bugsnag.notify(error)
return shouldUpdateRequestMetadata ? dispatch({ type: REQUEST_FAILED }) : null
}
}
}
export const downloadGoogleDriveBackup = () => {
return async dispatch => {
dispatch({ type: START_REQUEST });
try {
await GoogleSignin.signInSilently()
const token = await GoogleSignin.getTokens();
console.log('token', token)
GDrive.setAccessToken(token.accessToken);
GDrive.init();
// Gets the id of the first folder with the specified name and parents, creating the folder if it doesn't exist.
const folderId = await GDrive.files.safeCreateFolder({ name: BACKUP_FOLDER_NAME, parents: ['root'] });
console.log('folderId', folderId)
// Gets the id of the first file with the specified metadata.
const fileId = await GDrive.files.getId(BACKUP_FILE_NAME, ['root', folderId], "application/json", false);
console.log('fileId', filed) // even with a file existing inside the folder this return undefined
if (typeof fileId === 'undefined') {
return dispatch({ type: REQUEST_FAILED });
}
const response = await GDrive.files.get(fileId, { alt: 'media' });
const backup = await response.json();
dispatch({ type: FETCH_REMOTE_MOODS, payload: backup.moods });
dispatch({ type: FETCH_REMOTE_ROUTINES, payload: backup.routines });
dispatch({ type: FETCH_REMOTE_USERINFO, payload: backup.userInfo });
dispatch({ type: FETCH_REMOTE_ACTIVITIES, payload: backup.activities });
dispatch({ type: FETCH_REMOTE_CHALLENGES, payload: backup.challenges });
dispatch({ type: FETCH_REMOTE_GRATITUDE_JOURNAL, payload: backup.gratitudeJournal });
// notify that the request completed succesfully
return dispatch({ type: REQUEST_SUCCESSFUL });
} catch (error) {
bugsnag.notify(error)
return dispatch({ type: REQUEST_FAILED })
}
}
}
I tested 2 case:
I'm having problems like this:
"{"error": {"code": 403, "errors": [[Object]], "message": "The granted scopes do not give access to all of the requested spaces."}}"
GDrive.files
.list({
q: "'appDataFolder' in parents",
})
.then((res) => res.json())
.then((data) => console.log(data))
.catch((err) => console.log(err));
but when I try to create the file it works and returns status 200 using:
GDrive.files
.createFileMultipart(
content,
'application/json',
{
parents: ['appDataFolder'],
name: 'confbackup.json',
},
false,
)
.then((r: any) => console.log(r));
.catch((e: any) => console.log(e));
Any solution?
I try to createFileMultipart using the example but it returnes 400?
Any example how can i upload files on Gdrive please?
Hello, I want to get thumbnail url of PDF file from Google drive, but it doesn't work.
however a few months ago it was work.
let queryParams = {
fields : "thumbnailLink",
alt: "media"
}
GDrive.files.get('1ouH2LojK4Od46peKclyCnOOyILeWkCBz', queryParams)
.then((res)=>{
console.log(res.url)
}).catch((err)=>alert(err))
Result
"url": "https://www.googleapis.com/drive/v3/files/1I-ocFNkjjCtMcVel2tzVPugClv0TpU8F?fields=thumbnailLink&alt=media"}
but the url should be like this:
https://lh3.googleusercontent.com/d/1ouH2LojK4Od46peKclyCnOOyILeWkCBz?authuser=0
Hi!
Amazing package and so useful, thanks for that!
I am creating a folder called Moodflow. Then saving a file inside of it with .createFileMultipart()
.
However, I am not sure how to set the parents
property since it is an array.
Should it be ['root/Moodflow']
or ['root', 'Moodflow']
?
Thanks in advance!
Nevermind found the solution:
folderId
using .safeCreateFolder()
.const folderId = await GDrive.files.safeCreateFolder({ name: "Moodflow", parents: ["root"] });
['root', folderId]
const createdFile = await GDrive.files.createFileMultipart(
JSON.stringify(appStateToUpload),
"application/json",
{ parents: ['root', folderId], name: "Moodflow Backup" }
);
Hi there,
We have been using rn-gd-api-wrapper for a while and the uploading files to a shared drive functionality has stopped working in our project.
Uploading files to the user's drive works, but uploading it to a shared drive using the drive's id returns a 404 error.
This is our code:
uploadFile: async function (file, callback) {
const params = {
files: {
boundary: 'foo_bar_baz',
},
};
GDrive.init(params);
if (GDrive.isInitialized()) {
GDrive.files
.createFileMultipart(
file.content,
file.mimeType,
{
parents: file.parents,
name: file.name,
},
true,
)
.then((res) => {
console.log(res);
return callback(res);
});
}
},
Where file :
{ "content": CONTENT, mimeType": "application/pdf", "name": NAME, "parents": [IDSHAREDDRIVE], "path": PATH` }
The result is ( console.log(res) ):
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": BLOBID, "offset": 0, "size": 306}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": BLOBID, "offset": 0, "size": 306}}, "bodyUsed": false, "headers": {"map": {"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"", "content-length": "306", "content-type": "application/json; charset=UTF-8", "date": "Wed, 30 Jun 2021 13:39:17 GMT", "server": "UploadServer", "vary": "Origin, X-Origin", "x-guploader-uploadid": ID}}, "ok": false, "status": 404, "statusText": undefined, "type": "default", "url": "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"}
We obtain the session token using GoogleSignin and all the necessary permissions for the shared drive are applied correctly, it worked until a while ago. Folders are also created within the shared drive but the file upload fails.
What could be te problem?
Cheers!
This is my code
const token = await GoogleSignin.getTokens();
GDrive.setAccessToken(token.accessToken);
GDrive.init();
try {
console.log(
await (await GDrive.files.get(
await GDrive.files.getId("Customize.js", ["root"]), { alt: "media" })
).text()
);
} catch (e) {
console.log(e);
}
I am getting response as
{
type: 'default',
status: 403,
ok: false,
statusText: undefined,
headers:
{ map:
{ 'alt-svc': 'quic=":443"; ma=2592000; v="46,43,39"',
server: 'GSE',
'x-xss-protection': '1; mode=block',
'x-frame-options': 'SAMEORIGIN',
'x-content-type-options': 'nosniff',
'cache-control': 'private, max-age=0',
expires: 'Wed,
17 Jul 2019 07: 14: 57 GMT',
date: 'Wed,
17 Jul 2019 07: 14: 57 GMT',
'content-type': 'application/json; charset=UTF-8',
vary: 'X-Origin'
}
},
url: 'https: //www.googleapis.com/drive/v3/files?q=name=%22Customize.js%22%20and%20trashed=false%20and%20%27root%27%20in%20parents',
_bodyInit:
{ _data:
{ size: 962,
offset: 0,
blobId: 'f9c6007e-3d3d-421a-b56a-bca2151625b9'
}
},
_bodyBlob:
{ _data:
{ size: 962,
offset: 0,
blobId: 'f9c6007e-3d3d-421a-b56a-bca2151625b9'
}
}
}
@RobinBobin help me please,
I want to get an image-type jpg from google drive. Can you suggest some ideas?
const image = await googleDriver.files.getBinary(
"1aWCXGJAd7Ke8q9TCXsE5kMbSdlhQxucV", //field id
null,
"1-100000"
);
GDrive.setAccessToken(this.state.authToken);
GDrive.init();
GDrive.isInitialized() ? console.log(true) : console.log(false);
let list = await GDrive.files.list({
q:"type:image",
});
console.log(list);
when i pass images in query params response is like this
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "d847725e-e774-47c1-8c8f-ee7f0a982b4b", "offset": 0, "size": 249}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "d847725e-e774-47c1-8c8f-ee7f0a982b4b", "offset": 0, "size": 249}}, "bodyUsed": false, "headers": {"map": {"alt-svc": "h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"", "cache-control": "private, max-age=0", "content-security-policy": "frame-ancestors 'self'", "content-type": "application/json; charset=UTF-8", "date": "Tue, 30 Jun 2020 12:28:48 GMT", "expires": "Tue, 30 Jun 2020 12:28:48 GMT", "server": "GSE", "vary": "Origin, X-Origin", "www-authenticate": "Bearer realm="https://accounts.google.com/\", error=invalid_token", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", "x-xss-protection": "1; mode=block"}}, "ok": false, "status": 401, "statusText": undefined, "type": "default", "url": "https://www.googleapis.com/drive/v3/files?q=type:image"}
Hi, Robin.
You can just add one line (or add new createFileMultipartBase64 function) for base64 support.
in Files.js -> createFileMultipart()
just one additional header:
Content-Transfer-Encoding: base64\n\n
;
It would be nice to have that feature because react-native-fs reads binary files (and images) in base64 only.
https://github.com/alp1396/react-native-google-drive-api-wrapper/commit/f3b10c5f85fd9de8ea05c3a04d33a2434f1ab933
GDrive.files.list({}).then((result) => { console.log('file', JSON.parse(result)); }); });
In this code, the result is not JSON, and also cannot be parsed as a JSON
Is there a way to update the content of already uploaded file rather than just metadata?
The official documentation for update says it can be used to update a file's metadata OR content, I was wondering if we have the option to add content in the update using this wrapper?
Thanks
I have an error when try to use your lib to control file with google driver, you can check it in my repository in this link below
https://github.com/Dat0318/RN_example_firebase
i am follow a tutorial to use your lib
https://aboutreact.com/react-native-google-drive/
i looking forwards your feedbacks.
Thanks a lots.
bodyUsed: false
headers: Headers
map:
alt-svc: "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
cache-control: "private, max-age=0"
content-security-policy: "frame-ancestors 'self'"
content-type: "application/json; charset=UTF-8"
date: "Sun, 08 Aug 2021 10:55:00 GMT"
expires: "Sun, 08 Aug 2021 10:55:00 GMT"
server: "GSE"
transfer-encoding: "chunked"
vary: "Origin, X-Origin"
www-authenticate: "Bearer realm=\"https://accounts.google.com/\", error=insufficient_scope, scope=\"https://www.googleapis.com/auth/drive\""
x-content-type-options: "nosniff"
x-frame-options: "SAMEORIGIN"
x-xss-protection: "1; mode=block"
[[Prototype]]: Object
[[Prototype]]: Object
ok: false
status: 403
statusText: ""
type: "default"
url: "https://www.googleapis.com/drive/v3/files?q=name=%22AboutReactAppExample%22%20and%20trashed=false%20and%20mimeType=%22application/vnd.google-apps.folder%22%20and%20%27root%27%20in%20parents"
_bodyBlob: Blob
_data:
blobId: "86a7ff9e-1beb-4369-bb87-252ff8c7ff0a"
offset: 0
size: 306
__collector: null
[[Prototype]]: Object
data: (...)
size: (...)
type: (...)
[[Prototype]]: Object
_bodyInit: Blob
_data: {size: 306, offset: 0, blobId: "86a7ff9e-1beb-4369-bb87-252ff8c7ff0a", __collector: null}
data: (...)
size: (...)
type: (...)
[[Prototype]]: Object
[[Prototype]]: Object
how can we create new folders in drive? previously this was the method:
let response = await GDrive.files.safeCreateFolder({ name: GLOBAL.GOOGLE_DRIVE.TARGET_FOLDER_NAME, parents: ['root'], });
Hey Robin! This package has helped me out a lot. Thank you!
I don't know if it is a bug or it's just me who is not doing something right but on Android, I back up a copy of the apps state into GDrive every time the app initializes.
async onBackupData() {
const isUserLoggedIn = await GoogleSignin.isSignedIn();
console.log('isUserLoggedIn', isUserLoggedIn)
if (!isUserLoggedIn) return false;
try {
const userInfo = await GoogleSignin.signInSilently();
console.log('userInfo from .signInSilently', userInfo);
GoogleSignin.clearCachedToken()
.then(() => {
GoogleSignin.getTokens()
.then(tokenObject => {
return this.props.createNewGoogleDriveBackup(tokenObject.accessToken, { ...this.props.appState });
})
.catch(err => console.log('error', err));
})
.catch(error => console.log('error clearing cached token', error));
} catch (error) {
console.log('error', error)
}
}
I get the following error: SIGN_IN_REQUIRED
This is only happening on Android.
Am I missing something?
Hey,
i wonder if its possible to receive modifiedTime directly as a result when creating a file via createFileMultipart?
Currently i create the file then get modifiedTime with GDrive.files.get(adapterId, {fields: 'modifiedTime'})
which means two API calls.
I've seen that there is a date
field in the response header for createFileMultipart
:
"date": "Thu, 14 Nov 2019 11:38:19 GMT"
but i don't know if this is always the same as modifiedTime.
I also haven't found anything in the docs from google so i thought i might ask the question here. :)
Thanks in advance!
Hi everyone.
I try it with ExternalDirectoryPath and DocumentDirectoryPath. Both of them i got same error
"dependencies": {
"firebase": "^7.14.1",
"react": "16.8.6",
"react-native": "0.60.5",
"react-native-firebase": "^5.6.0",
"react-native-fs": "^2.13.2",
"react-native-google-drive-api-wrapper": "^1.2.0",
"react-native-google-signin": "^2.0.0"
},
"devDependencies": {
"@babel/core": "7.9.0",
"@babel/runtime": "7.9.2",
"@react-native-community/eslint-config": "0.0.3",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.6"
},
Hello Robin, I have a problem that I can not solve. I need to upload files to google drive. I have authenticated with react-native-google-signin.
But how do I get ACCES_TOKEN? I always have this 401 error.
Cannot build after installing.
npm i --save react-native-google-drive-api-wrapper
react-native link react-native-fs
Try npm install @types/react-native-google-drive-api-wrapper
if it exists or add a new declaration (.d.ts) file containing declare module 'react-native-google-drive-api-wrapper';
[7016]
I want to pass fields parameter to get method to get all the meta data. How can it be done?
I have tried.
GDrive.files.get(fileId, {
fields: "*"
})
Here is the url generated https://www.googleapis.com/drive/v3/files/?fields=title
how to show or get image from drive without knowing file id
Like in Google Drive i can share and get a shareable link...
i ca get a link over here also, but i want to share the file if it is not shared in my google drive !
@RobinBobin Can you support me get content file with mimeType = "application/xml"
my Code get xml file to reponse Blob :
File has mimeType = "plain/text" . but mimeType = "text/xml" I can get text content .
@RobinBobin would you suggest me some ideas?
const xml = await googleDriver.files.get(file.id, { alt: "media" });
var blobs = xml._bodyBlob;
const text = await this.blobToBase64(blobs);
console.log(text);
blobToText = (blob) => {
const reader = new FileReader();
reader.readAsText(blob);
return new Promise((resolve) => {
reader.onloadend = () => {
resolve(reader.result);
};
});
};
I want to get the content of the file XML from Google Drive.
First of all thanks for your awesome work. Really appreciated.
I am using GDrive to list the files in the user's drive but it gives me an error without any description.
Here is my program for the same.
googleDriveViewFile = async () => {
if (!GoogleSignin.isSignedIn) {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
console.log(userInfo);
} catch (error) {
console.log(error);
}
}
const gdrive = new GDrive();
gdrive.accessToken = (await GoogleSignin.getTokens()).accessToken;
console.log(
await gdrive.files.list({
q: new ListQueryBuilder()
.e('name', 'Untitled')
.and()
.in('root', 'parents'),
}),
);
};
And I call my configure method on didmount.
This is the error I get in my console.
Error
construct@[native code]
_construct@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:6622:28
Wrapper@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:6575:64
construct@[native code]
_createSuperInternal@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:110290:322
HttpError@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:110303:26
create$@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:110342:38
tryCatch@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7707:23
invoke@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7880:32
tryCatch@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7707:23
invoke@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7780:30
http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7810:19
tryCallTwo@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:28582:9
doResolve@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:28746:25
Promise@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:28605:14
callInvokeWithMethodAndArg@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7809:33
enqueue@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7814:157
async@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7831:69
create@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:110338:42
_callee$@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:110936:76
tryCatch@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7707:23
invoke@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7880:32
tryCatch@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7707:23
invoke@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7780:30
http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:7790:21
tryCallOne@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:28573:16
http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:28674:27
_callTimer@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:29090:17
_callImmediatesPass@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:29129:17
callImmediates@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:29347:33
__callImmediates@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:3229:35
http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:3007:34
__guard@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:3212:15
flushedQueue@http://192.168.0.106:8081/index.bundle?platform=android&dev=true&minify=false&app=com.reactnativesampleapp&modulesOnly=false&runModule=true:3006:21
flushedQueue@[native code]
callFunctionReturnFlushedQueue@[native code]
This is how I am sharing a file:
GDrive.permissions.create( FILE_ID, { role: "reader", type: "user", emailAddress: SOME_EMAIL_ADDRESS } );
But I keep getting this Delivery Status Notification(Failure) email. The file is, however, successfully shared.
How do I stop getting these emails? I do not want any failure acknowledgment email. My requirement is that even if the sharing fails, I should not receive any such email.
Hello @RobinBobin i want to uploadvideo on google drive. I got error 400.
Hello,
As per https://www.npmjs.com/package/react-native-google-drive-api-wrapper document
GDrive.files.getId(
name: String, // The name.
parents: [String], // The parents.
mimeType: String, // The mime type.
trashed: Boolean // Whether the file is trashed. Default: false
);
I used this function as
GDrive.files.getId(fileName, false )
.promise.then((r)=>{
console.log(r);
});
But it is showing error
` The type cast expression is expected to be wrapped with parenthesis (60:9)
58 | getFileId(fileName){
59 | GDrive.files.getId(
60 | name: fileName,
| ^
61 | trashed: false )
62 | .promise.then((r)=>{
63 | console.log(r);`
Someone Kindly help me , Thanks in advance
How can we query which excludes files from the trash folder?
Currently files are included using listquerybuider
Hi,
First of all this plugin is very useful to interact with google drive and upload files to the same after authentication.
I am able to upload normal text file to google drive.
But now the point is how to upload PDF file to google drive. Do I need to convert its content to base64 and then upload or is there any other way.
let contents = "http://xyz.com/" + this.state.pdf;
GDrive.files.createFileMultipart(
contents,
"application/pdf", {
name: "My file"
}).then((data) => {
console.log('reponsee in then ' + JSON.stringify(data));
});
"contents" variable contain root path where pdf file is stored.
Please help and let me know if any other information is required.
Thanks
I am unable to get the web view link to the file. I am using the get method available. But there is no example/clear documentation with respect to how to use it to get the required data.
const getFile = async (fileId) => { const gdrive = new GDrive(); gdrive.accessToken = (await GoogleSignin.getTokens()).accessToken; try { let queryParams = { fields : "webViewLink", } let list = await gdrive.files.get(fileId, queryParams) console.log(list) } catch (error) { console.log(JSON.stringify(error)) } }
Heres the code I have. The success code is 200 but in the response I am not receiving the web view url
I got 403 error while createFileMultipart.
The google sign in is working, but drive api does not work.
Here is Google Signin Scrips and Drive Api call script.
await GoogleSignIn.configure({ scopes: ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.appdata', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.metadata', ], shouldFetchBasicProfile: true, offlineAccess: true });
let res = await GDrive.files.createFileMultipart("My File Contents", "text/plain", { parents: ['root'], name: "myfile" })
Hello,
How can i make dynamic folder and upload our video images in this folder. please suggest me.
Thanks in advance
I'm not able to upload the media(video) other the Base64 format, base64 is causing app crash, due to over file size, can you please tell me how should I upload it to google drive
@RobinBobin help me, please!
const id = (
await googleDriver.files
.newMultipartUploader()
.setData(BBImage, "image/jpg")
.setRequestBody({
name: "image_123",
})
.execute()
).id;
console.log(id);
hello, I want to get list of files from shared drive, but its desn't work
await GoogleSignin.getTokens().then(res=>GDrive.setAccessToken(res.accessToken))
GDrive.init()
await GDrive.files.list({
q: "mimeType='application/pdf'",
fieIds:'*',
corpora:'drive',
supportsAllDrives:true,
includeItemsFromAllDrives:true,
driveId:'1YAyXfzIAOP5TejUW00RR9jhXaBIXKF8_'
})
.then(res=>res.json())
.then(data=>console.log(data))
.catch(err=>console.log(err))
this error occured:
{"error": {"code": 404, "errors": [[Object]], "message": "Shared drive not found: 1YAyXfzIAOP5TejUW00RR9jhXaBIXKF8_"}}
fixed 😆
I provided folderId instead driveId, so you have to change query like this:
GDrive.init()
GDrive.files.list({
q: "' folderId ' in parents",
})
.then(res=>res.json())
.then(data=>console.log(data))
.catch(err=>console.log(err))
Hello, I have a problem when I try to export a file from Google Drive. When I try to export any file I always get this error.
This is the function I use for exporting this file.
This file I created in the API test, and I can not export it myself.
Google drive API is already enabled.
I really do not know why I get error 403
Anything for expo users?
I'm very interested in using this project for auto-uploading hidden backup files to the users Google Drive. This backup occurs infrequently. Sometimes during the same sessions, or often during multiple app sessions (where the device may be rebooted, or app force killed, suspended etc). So I'm wondering how long does the GDrive access token stay alive? I would like to minimise the number of signins as possible, because I feel this may not be good UX.
When i use upload, it return code: 0. I think it cause by AbortController.
Can you check it again sir? Thank you so much.
try {
const res = await driver.files
.newMultipartUploader()
.setData(base64, "'image/jpg'")
.setRequestBody({
name: imageName,
mimeType: 'image/jpg',
parents: [folderId],
})
.setIsBase64(true)
.execute();
} catch (err) {
console.log('Upload file error: ', err);
throw err;
}
It has been almost 4 months that my code was working completely fine. But now, suddenly I am not able to upload file on any folder in Google drive via React Native app. I don't think that this is an issue of exceeding limits or something, because I am able to upload file on root folder, but not to any folder/subfolder.
Error is:
403 Increasing the number of Parents is not allowed Google Drive API React Native
Log:
{"error":{"errors":[{"domain":"global","reason":"cannotAddParent",
"message":"Increasing the number of parents is not allowed"}],
"code":403,"message":"Increasing the number of parents is not allowed"}}
When I posted this on StackOverflow, I got to know that Google drive API is updated. So how am I suppose to add a file in the subfolder please help?
https://stackoverflow.com/questions/64482189/403-increasing-the-number-of-parents-is-not-allowed-google-drive-api-react-nativ
Can't get plain/text file content.
Source code given below
GDrive.setAccessToken(this.props.userGoogleAuthInfo.accessToken); GDrive.init(); GDrive.isInitialized() ? console.log('Gdrive initialized') : console.log('Gdrive not initialized'); GDrive.files.get(fileId, {alt: "media"}).then(res => { console.log(res); }).catch(e => { console.log(e); })
response was
headers: Headers {map: {…}} ok: true status: 200 statusText: undefined type: "default" url: "https://www.googleapis.com/drive/v3/files/1M5aPXRDrREF5zQaoq28m1alW4BgPIREH?alt=media" _bodyBlob: Blob _data: blobId: "9247a753-52ff-4d33-9139-64aa582ba468" offset: 0 size: 53376 __proto__: Object data: (...) size: (...) type: (...) __proto__: Object _bodyInit: Blob {_data: {…}}
I don't have any idea. my another testing project working fine. is it google project setup issue or something?.
Hello evebody, i was using this api, but, in call gdrive.files.list it's returned this response.
{"__response":{"type":"default","status":401,"ok":false,
...
"code":401,"message":"Invalid Credentials"
But my credentials i am utilizing this way
GoogleSignin.configure({
webClientId: this credential i was generate in google api console,
offlineAccess: true,
scopes: [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file'
],
})
And i had called this way
await gdrive.files.list({
"corpus": "user",
"includeItemsFromAllDrives": true,
"includeTeamDriveItems": true,
"supportsAllDrives": true,
"supportsTeamDrives": true
}).then(res => {
console.log(1, res.json())
}).catch(err => {
console.log(2, JSON.stringify(err))
})
Someone to know what i made wrong?
response is success but it is not showing any list of files.
let files = await GDrive.files.list({ "corpus": "user", "includeItemsFromAllDrives": true, "includeTeamDriveItems": true, "supportsAllDrives": true, "supportsTeamDrives": true }); console.log("files",files)
Response -> {headers: Headers
map: {alt-svc: "quic=":443"; ma=2592000; v="46,43",h3-Q049=":443";…046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000", server: "GSE", x-xss-protection: "1; mode=block", x-frame-options: "SAMEORIGIN", x-content-type-options: "nosniff", …}
proto: Object
ok: true
status: 200
statusText: undefined
type: "default"
url: "https://www.googleapis.com/drive/v3/files?corpus=user&includeItemsFromAllDrives=true&includeTeamDriveItems=true&supportsAllDrives=true&supportsTeamDrives=true"
_bodyBlob: Blob {_data: {…}}
_bodyInit: Blob {_data: {…}}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.