Hướng dẫn ruby google sheets - trang tính ruby google
1. Google developer console1.1 Tạo new projectĐăng nhập vào https://console.developers.google.com/?angularJsUrl= Trên thanh header chọn [Select a project] để tạo mới project Show
Ví dụ như mình đã tạo google-sheet-api 1.2 Enable APIs and ServiceChọn project: google-sheet-api Click vào Enable APIs and Service Để xuất hiện màn hinh bên dưới. Tiếp đó tìm APIs và Service của Google driver API và Google sheet API để Enable nó lên Enable APIs and Service Để xuất hiện màn hinh bên dưới. Tiếp đó tìm APIs và Service của Google driver API và Google sheet API để Enable nó lên Sau đó click vào Google APIs để về trang chủ và chọn Credentials Click vào Create credentials và chọn option Service account keyhttps://images.viblo.asia/316f0e00-8343-4889-94ac-d6e53965756c.pngCredentials Click vào Create credentials và chọn option Service account key https://images.viblo.asia/316f0e00-8343-4889-94ac-d6e53965756c.png Sau đó tạo service name của bạn và chọn role rồi create vào Create để download key về máy rồi create vào Create để download key về máy 2. Tạo Project google-sheet-apiTạo thư mục project: Di chuyển key vừa download lúc nãy vào thư mục Di chuyển tới thư mục project Tạo Gemfile Tạo file spreadsheet 2.1. GemfileThêm 0 và chạy 1 để cài đặt
2.2 Chuẩn bị file google sheet và share quyềnTiến hành share quyền cho email là value của key client_email trong file json client_secret.json mình tải về ban đầu đối với googlesheet mình muốn thao tác. client_email trong file json client_secret.json mình tải về ban đầu đối với googlesheet mình muốn thao tác. 3. Thao tác với google sheet3.1 Lấy dữ liệu từ google sheetLấy 3 dòng đầu và 2 cột
Chạy 2 ta có Kết quả3.2 Insert dữ liệu vào file googlesheet
Chạy 2 ta có Kết quả https://images.viblo.asia/0a94c2ef-8ffc-4b1e-bc92-1f163e720bf4.pnghttps://images.viblo.asia/0a94c2ef-8ffc-4b1e-bc92-1f163e720bf4.png3.3 Update dữ liệu file googlesheet
Chạy 2 ta có Kết quả 3.4 Remove dữ liệu file googlesheet
Chạy 2 ta có Kết quả
3.4 Remove dữ liệu file googlesheethttps://www.youtube.com/watch?v=VqoSUSy011I |