User

Để tạo một tệp JSON với thông tin xác thực OAuth2 như bạn đã cung cấp, bạn cần truy cập Google Cloud Console, tạo một dự án và cấu hình OAuth consent screen.

Dưới đây là các bước chi tiết:

Bước 1: Truy cập Google Cloud Console

  1. Mở trình duyệt web và truy cập Google Cloud Console.
  2. Đăng nhập vào tài khoản Google của bạn hoặc tạo một tài khoản mới nếu bạn chưa có.

Bước 2: Tạo Dự Án

  1. Nhấp vào biểu tượng "Select a Project" ở góc trên cùng bên phải của trang và chọn "New Project".
  2. Đặt tên cho dự án của bạn và nhấp vào "Create".

Bước 3: Chọn Dự Án

  1. Chọn dự án bạn vừa tạo ở thanh công cụ trên cùng.
  2. Chọn "APIs & Services" > "Dashboard" từ menu bên trái.
  1. Trong menu bên trái, chọn "APIs & Services" > "OAuth consent screen".
  2. Chọn "External" và nhấp "Create".
  3. Điền thông tin như tên ứng dụng, email liên hệ và các thông tin yêu cầu khác.
  4. Thêm phạm vi truy cập (scopes) nếu cần thiết và lưu lại.

Bước 5: Tạo Credentials

  1. Chọn "Credentials" trong menu bên trái.
  2. Chọn "Create Credentials" > "OAuth client ID".
  3. Chọn "Desktop app" hoặc "Other" tùy thuộc vào ứng dụng của bạn.
  4. Nhập tên và nhấp "Create".
  5. Sao chép Client ID và Client Secret.

Bước 6: Cấu hình Redirect URI

  1. Trong mục "Authorized redirect URIs", thêm "http://localhost" vào danh sách.

Bước 7: Tạo Tệp JSON

  1. Nhấp vào biểu tượng bút chì để chỉnh sửa thông tin.
  2. Chọn "Download JSON" để tải xuống tệp JSON chứa thông tin xác thực.

Lưu ý:

  • Bảo mật: Bảo vệ tệp JSON này và không bao giờ chia sẻ nó công khai hoặc lưu trữ nó ở nơi không an toàn.
  • Scopes: Nếu ứng dụng của bạn cần quyền truy cập đến các dịch vụ cụ thể, hãy thêm phạm vi truy cập (scopes) trong mục OAuth consent screen và chọn đúng phạm vi khi tạo Credentials.

Lưu ý rằng thông tin này có thể cũng được quản lý trong trang [API & Services] > [Credentials] trên Google Cloud Console sau khi tạo xong.

token.pickle

How Reading data from GoogleSheet:

Các bước các bạn cần làm khi triển khai bao gồm các bước sau:

1> Cài đặt thư viện:

pip install rf-googlesheetslibrary==0.2

2> Bỏ file data vào thư mục chung này:

https://drive.google.com/drive/…

3> Lấy sheet id bỏ vào file biến:

update sheet id vao file : common_variable.py

4> Đặt file token.pickle vào thư mục: C:\token trong máy local của các bạn:

5> Sử dụng keyword đọc data từ googleSheet:

dùng keyword này: Connect To GoogSheet and Get Data

tham khảo cách dùng từ keyword

Các bước liên quan tới setup sử lý authen với googleSheet ( cái này các bạn manual ko cần làm)

1> Request IT tạo cho 1 G-suite account

2> Request bên cloud tạo cho 1 file credential.

3> dùng code của robot theo link hướng dẫn ( https://mainsystemdev.github.io/GoogleSheetsLibrary/#Append Values) để tạo ra 1 file token.pickle

4> Cài đặt thư viên: pip install rf-googlesheetslibrary==0.2

5> Dùng các keyword có sẵn của thư viện googleSheetLibrary (https://pypi.org/project/rf-googlesheetslibrary/ )

Tham khảo các link ở dưới

https://pypi.org/project/rf-googlesheetslibrary/

https://mainsystemdev.github.io/GoogleSheetsLibrary/#Append Values

https://robocorp.com/docs/development-guide/google-sheets/interacting-with-google-sheets

https://docs.gspread.org/en/latest/oauth2.html#enable-api-access-for-a-project

https://onemountgroup.slack.com/archives/CLHQCDLRF/p1646277749790869

https://console.cloud.google.com/apis/credentials?project=vinid-qc-nonprod

Account để sharing các file google sheet: [email protected] ( account này Trương Ba [email protected] cấp)

Chú ý, sau 1 thời gian : token.pickle sẽ bị hế hạn, phải chạy lại file GoogleSheet.py để nó gen ra file mới

Chú ý phải có file credentials.json trong cùng 1 thư mục, file Credentials.json này được tạo ra từ bước ở trên

đặt file credentials.json vào trong thư mục: C:\token, tạo biến môi trường: GOOGLESHEET_CREDENTIALS

Chạy file GoogleSheet.py để nó gen ra file token.pickle:

Initializes the connection to the specified Google Spreadsheet. Takes 2 positional arguments spreadsheetId and tokenFile. Sample Usage:

Certainly! To initialize a connection to a Google Spreadsheet using Python, you can use the gspread library along with the Google Sheets API. Make sure you have the library installed before using it:

pip install gspread

Here's a sample code snippet for initializing the connection to a Google Spreadsheet:

import gspread
from google.oauth2.service_account import Credentials

def initialize_spreadsheet_connection(spreadsheet_id, token_file):
    # Load credentials from the specified token file
    credentials = Credentials.from_service_account_file(token_file, scopes=["https://www.googleapis.com/auth/spreadsheets"])
# Authorize the credentials
gc = gspread.authorize(credentials)

# Open the specified spreadsheet by its ID
spreadsheet = gc.open_by_key(spreadsheet_id)

return spreadsheet

Sample Usage
spreadsheet_id = "your_spreadsheet_id"
token_file = "path/to/your/token/file.json"
Initialize the connection
spreadsheet_connection = initialize_spreadsheet_connection(spreadsheet_id, token_file)
Now you can use the 'spreadsheet_connection' object to work with your Google Spreadsheet

trả về index của 1 list mà tổng của phần tử thứ 0 tới index đó lớn hơn một giá trị

Sắp xếp theo giá trị tăng dần của 1 list

Thêm key, value vào dictionary trong robot framework

Thêm key, value vào dictionary trong robot framework

Viết chương trình robot framework, có 1 dictionary, sắp xếp theo thứ tự lớn dần của value