From 22b33e3a410f8a1fb628907b6f946d2d4447c840 Mon Sep 17 00:00:00 2001 From: Negrah Date: Fri, 9 Jun 2023 18:23:08 +0530 Subject: [PATCH 1/2] updated nextjs code --- src/Googledrive#98/Readme.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Googledrive#98/Readme.md diff --git a/src/Googledrive#98/Readme.md b/src/Googledrive#98/Readme.md new file mode 100644 index 0000000..eaa174c --- /dev/null +++ b/src/Googledrive#98/Readme.md @@ -0,0 +1,35 @@ +'' = to be writen in bash / Terminal +" " = jsx code +1) Set up a Next.js project: +Initialize a new Next.js project by running the following commands in your terminal: +' npx create-next-app my-google-drive-plugin +cd my-google-drive-plugin ' +2) Install dependencies: +Install the required dependencies for interacting with the Google Drive API by running the following command: +' npm install googleapis ' +3) Create the storage plugin component: +In the pages directory of your Next.js project, create a new file called googleDrivePlugin.js and implement the storage plugin component with the integration code. Here's an example implementation: +# Attached as seprate file we need to Replace 'path/to/credentials.json' with the actual path to your Google Drive API credentials file. +4) Update the Next.js page: +In the pages directory, modify the index.js file to include the GoogleDrivePlugin component: +" import GoogleDrivePlugin from './googleDrivePlugin'; + +export default function Home() { + return ( +
+

My Next.js App

+ +
+ ); +} +" +5) Run the Next.js development server: +Start the Next.js development server by running the following command in your project's root directory: +'npm run dev ' +This will start the server and display the output in your browser at http://localhost:3000. + +# The GoogleDrivePlugin component in the googleDrivePlugin.js file demonstrates an example of listing files in Google Drive. We can extend it by adding more API calls and functionality based on our specific requirements. + +Please note that this is a basic implementation to get us started. Depending on our needs, we may need to handle authentication, implement file upload/download functionality, and handle API responses more robustly. + + From be097ed82357051178a7c74da33f3e81a9ab48b8 Mon Sep 17 00:00:00 2001 From: Negrah Date: Fri, 9 Jun 2023 18:23:31 +0530 Subject: [PATCH 2/2] documentation for code --- src/Googledrive#98/googleDrivePlugin.js | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Googledrive#98/googleDrivePlugin.js diff --git a/src/Googledrive#98/googleDrivePlugin.js b/src/Googledrive#98/googleDrivePlugin.js new file mode 100644 index 0000000..822256f --- /dev/null +++ b/src/Googledrive#98/googleDrivePlugin.js @@ -0,0 +1,40 @@ +import { useEffect } from 'react'; +import { google } from 'googleapis'; + +export default function GoogleDrivePlugin() { + useEffect(() => { + // Initialize Google Drive API client + const auth = new google.auth.GoogleAuth({ + keyFile: 'path/to/credentials.json', + scopes: ['https://www.googleapis.com/auth/drive'], + }); + + const drive = google.drive({ version: 'v3', auth }); + + // Example: List files in Google Drive + const listFiles = async () => { + try { + const response = await drive.files.list({ + pageSize: 10, + fields: 'nextPageToken, files(name, webViewLink)', + }); + + const files = response.data.files; + if (files.length) { + console.log('Files in Google Drive:'); + files.forEach((file) => { + console.log(`${file.name} (${file.webViewLink})`); + }); + } else { + console.log('No files found in Google Drive.'); + } + } catch (error) { + console.error('Error listing files in Google Drive:', error); + } + }; + + listFiles(); + }, []); + + return
Google Drive Plugin
; +}