Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PR for #98 #158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Googledrive#98/Readme.md
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<h1>My Next.js App</h1>
<GoogleDrivePlugin />
</div>
);
}
"
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.


40 changes: 40 additions & 0 deletions src/Googledrive#98/googleDrivePlugin.js
Original file line number Diff line number Diff line change
@@ -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 <div>Google Drive Plugin</div>;
}