Lập trình Android sử dụng Gmail API

quick start

lấy sha1 từ keystore keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v

trong đó Androiddebugkey Chính Là tên aias của keystore của bạn tạo ký app

ok, giờ bạn có sha1 với package của project android bạn rồi, vào console.developers.google.com setting thôi

từng bước setting thế nào bạn không biết xem ở link quickstart của google: https://developers.google.com/gmail/api/quickstart/android (step 2 đó, trên là mình giải thích về step 1 của link train)

còn bạn làm tiếp Step 3+4+5 bạn sẽ có 1 project ơn giản lấy danh Sách các tag lter) /p>

with 2 điều chú ý nhỏ:

  • gmail api chỉ hỗ trợ từ api 11: android 3.0 (honeycomb) trở lên nhé
  • scope: private static final string[] scopes = { gmailscopes.gmail_labels };

Đoạn code này khai báo chỉ được lấy label của gmail. tức nếu bạn chỉ khai báo trên muốn send mail hay lấy mail về là không được. muốn dùng bạn phải khai báo thêm scope.

Đây là danh sách các scope: (mình lấy trong class gmailscopes đó, muốn xem kỹ hơn, mở file đó mà xem nhé)

mail_google_com: View and manage your mail. gmail_compose: manage drafts and send emails. gmail_insert: insert the mail in your mailbox. gmail_labels – Manage mailbox labels. gmail_metadata – View the metadata of your email message, such as labels and headers, but not the body of the email. gmail_modify: view and modify but not delete your email. gmail_readonly – View your email messages and settings. gmail_send: send email on your behalf. gmail_settings_basic – Manage your basic mail settings. gmail_settings_sharing – Manage your sensitive mail settings, including who can handle your mail.

See Also:  Comparing FedEx, UPS, and USPS | Red Stag Fulfillment

test api

Để dùng thử api bạn vào link sau: https://developers.google.com/gmail/api/v1/reference/ Ở bên phải có mục: try this api để mình test api giống như test postman đó. test api list trước để lấy danh sách rồi mới cái dưới nhé. À user id của chính mình là me nhé

Lập trình Android sử dụng Gmail API

demo

sau đây là demo của mình: làm ứng dụng email client đơn giản (lấy danh sách mail đến, gửi mail, trả lời mail – trả lời mail của mình chính l). Để làm ứng dụng đơn giản này, mình chỉ sử dụng scope gmailscopes.mail_google_com thôi nhé

  • nhận danh sách các mail: (inbox hộp)
  • gửi mail:

chi tiết để hiểu hơn, download the source code mình về mà xem nhé: https://github.com/quizsystem/gmailapi

Leave a Reply

Your email address will not be published. Required fields are marked *