- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
- [C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
[C#] Hướng dẫn đọc danh bạ Google sử dụng Google Contact API V3
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục chia sẽ và hướng dẫn các bạn cách đọc danh bạ email, điện thoại từ Google, sử dụng Google Contact API V3.
[C#] Đọc danh bạ từ Google sử dụng Google Contact API V3
Google Contact chắc không còn xa lạ với các bạn. Hiện các bạn nào đang sử dụng điện thoại Android thì thường đồng bộ danh bạ từ điện thoại lên Google Contact.
Và trong bài viết này mình sẽ sử dụng ngôn ngữ lập trình C#, để đọc danh bạ từ Email Google về ListView.
Giao diện Google Contact của Gmail của mình trên Google.
Và dưới đây là giao diện ứng dụng đọc danh bạ từ email của mình về Listview trong C#:
Bao gồm các thông tin cơ bản: Tên danh bạ, địa chỉ email và số điện thoại.
Hướng dẫn thực hiện:
Đầu tiên, từ thư viện Nuget Console các bạn cài đặt cho mình hai thư viện bên dưới vào.
Install-Package Google.Apis.Auth
Install-Package Google.GData.Contacts
Và dưới đây là Full Source code Read Contact Google Api V3 C#:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util.Store;
using Google.Contacts;
using Google.GData.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Google_Contact
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void auth()
{
string clientId = "461939640628-e514anaba9m17gaf215t272r11gd9dmo.apps.googleusercontent.com";
string clientSecret = "seUvbPkQXC3-9avB0QXfAN_B";
string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" };
try
{
// Use the current Google .net client library to get the Oauth2 stuff.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, "googleContact"
, CancellationToken.None
, new FileDataStore("googleContact")).Result;
// Translate the Oauth permissions to something the old client libray can read
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = credential.Token.AccessToken;
parameters.RefreshToken = credential.Token.RefreshToken;
RunContactsSample(parameters);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void RunContactsSample(OAuth2Parameters parameters)
{
try
{
RequestSettings settings = new RequestSettings("Google contacts tutorial", parameters);
ContactsRequest cr = new ContactsRequest(settings);
cr.Settings.PageSize = 1000;
var f = cr.GetContacts();
int i = 0;
ListViewItem item = new ListViewItem();
foreach (Contact c in f.Entries)
{
i++;
var name = c.Name.FullName;
var email = (from xemail in c.Emails select xemail.Address).FirstOrDefault();
var phone = (from xphone in c.Phonenumbers select xphone.Value).FirstOrDefault();
item = new ListViewItem(new string[] { i + ".", name, email, phone });
listView1.Items.AddRange(new ListViewItem[] { item });
}
}
catch (Exception a)
{
Console.WriteLine("A Google Apps error occurred.");
Console.WriteLine();
}
}
private void button1_Click(object sender, EventArgs e)
{
auth();
}
}
}
Video demo ứng dụng:
Thanks for watching!