RobinBobin / react-native-google-drive-api-wrapper

This wrapper facilitates the use of the Google Drive API in React Native projects.
110 stars 43 forks source link

Unable to get the metadata or the web view url #52

Closed lokeswarisatyanarayanan closed 3 years ago

lokeswarisatyanarayanan commented 3 years ago

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
RobinBobin commented 3 years ago

Have a look at gdrive.files.getMetadata().

lokeswarisatyanarayanan commented 3 years ago

I tried that. It returns an empty object with both queryParameters passed and no query parameters

RobinBobin commented 3 years ago

This code works for me.

function App() {
  useEffect(() => {
    GoogleSignin.configure({
      scopes: [
        "https://www.googleapis.com/auth/drive",
        "https://www.googleapis.com/auth/drive.appfolder"
      ]});

    (async () => {
      try {
        await GoogleSignin.hasPlayServices();
        await GoogleSignin.signIn();

        const gdrive = new GDrive();
        gdrive.accessToken = (await GoogleSignin.getTokens()).accessToken;

        console.log(await gdrive.files.getMetadata(
          fileId, {
            fields: "webViewLink"
          }
        ));
      } catch (error) {
        console.log("oops", error.toString());
      }

Is your setup correct? Can you write or read files?

lokeswarisatyanarayanan commented 3 years ago

It works! it was the scopes!

Thank you so much for the quick turn around time.