{"id":4524,"date":"2014-06-28T11:09:43","date_gmt":"2014-06-28T02:09:43","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=4524"},"modified":"2014-07-01T10:54:21","modified_gmt":"2014-07-01T01:54:21","slug":"gmail-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8bvba%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=4524","title":{"rendered":"Gmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed"},"content":{"rendered":"<p>\u300c<a href=\"http:\/\/www.atmarkit.co.jp\/ait\/articles\/1406\/27\/news140.html\" title=\"\u300cGmail API\u300d\u03b2\u7248\u516c\u958b\u3001\u9023\u52d5\u30a2\u30d7\u30ea\u958b\u767a\u3092\u652f\u63f4\" target=\"_blank\">\u300cGmail API\u300d\u03b2\u7248\u516c\u958b\u3001\u9023\u52d5\u30a2\u30d7\u30ea\u958b\u767a\u3092\u652f\u63f4<\/a>\u300d\u306b\u3082\u3042\u308b\u3088\u3046\u306b\u3001\u5148\u65e5<span style=\"color: #ff0000; font-weight: bold;\">Gmail API<\/span>\u304c\u3088\u3046\u3084\u304f\u516c\u958b\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u30fbGmail API &#8211; Google Developers<\/strong><br \/>\n<a href=\"https:\/\/developers.google.com\/gmail\/api\/\" title=\"Gmail API - Google Developers\" target=\"_blank\">https:\/\/developers.google.com\/gmail\/api\/<\/a><\/p>\n<p>\u3053\u306eAPI\u3092\u4f7f\u3048\u3070G\u30e1\u30fc\u30eb\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u8aad\u307f\u8fbc\u307f\u3084\u30e1\u30fc\u30eb\u9001\u4fe1\u304c\u3067\u304d\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u65e9\u901fVBA\u30de\u30af\u30ed\u304b\u3089\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h4>\u25a0 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u306e\u53d6\u5f97<\/h4>\n<p>API\u306e\u7d39\u4ecb\u3067\u3001<\/p>\n<blockquote><p>\nDesigned to let you easily deliver Gmail-enabled features, this new API is a standard Google API, which gives RESTful access to a user\u2019s mailbox under OAuth 2.0 authorization. It supports CRUD operations on true Gmail datatypes such as messages, threads, labels and drafts.<\/p><\/blockquote>\n<p><a href=\"http:\/\/googleappsdeveloper.blogspot.jp\/2014\/06\/introducing-new-gmail-api.html\" title=\"Introducing the new Gmail API - Google Apps Developer Blog\" target=\"_blank\">Introducing the new Gmail API &#8211; Google Apps Developer Blog<\/a> \u3088\u308a<\/p>\n<p>\u3068\u3042\u308b\u3088\u3046\u306b\u3001\u3053\u306eAPI\u306fOAuth 2.0\u8a8d\u8a3c\u3067RESTful\u306aAPI\u3067\u3059\u306e\u3067\u3001\u307e\u305a\u306f\u30de\u30af\u30ed\u304b\u3089OAuth 2.0\u8a8d\u8a3c\u3092\u884c\u308f\u306a\u304f\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n<p>\u8a8d\u8a3c\u65b9\u6cd5\u306f\u300c<a href=\"https:\/\/developers.google.com\/accounts\/docs\/OAuth2InstalledApp?hl=ja\" title=\"Using OAuth 2.0 for Installed Applications - Google Accounts Authentication and Authorization - Google Developers\" target=\"_blank\">Using OAuth 2.0 for Installed Applications &#8211; Google Accounts Authentication and Authorization &#8211; Google Developers<\/a>\u300d\u306b\u3042\u308b\u3088\u3046\u306b\u3001<\/p>\n<ol>\n<li>Google \u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u30b5\u30a4\u30f3\u30a4\u30f3\u3057\u307e\u3059\u3002<\/li>\n<li>\u627f\u8a8d\u5f8cAuthorization code\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<li>Authorization code\u3092\u5143\u306b\u767a\u884c\u3057\u305fAccess token\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_01.png\" alt=\"GmailAPI_01_01\" width=\"364\" height=\"377\" class=\"alignnone size-full wp-image-4525\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_01.png 364w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_01-289x300.png 289w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/developers.google.com\/accounts\/docs\/OAuth2InstalledApp?hl=ja\" title=\"Using OAuth 2.0 for Installed Applications - Google Accounts Authentication and Authorization - Google Developers\" target=\"_blank\">Using OAuth 2.0 for Installed Applications &#8211; Google Accounts Authentication and Authorization &#8211; Google Developers<\/a> \u3088\u308a<\/p>\n<p>\u3068\u3044\u3063\u305f\u6d41\u308c\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3053\u3067\u5fc5\u8981\u306b\u306a\u308b\u306e\u304c<span style=\"color: #ff0000; font-weight: bold;\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID<\/span>\u3068<span style=\"color: #ff0000; font-weight: bold;\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30b7\u30fc\u30af\u30ec\u30c3\u30c8<\/span>\u3067\u3001\u30de\u30af\u30ed\u3092\u66f8\u304f\u524d\u306b\u307e\u305a\u306f\u3053\u308c\u3089\u3092\u6e96\u5099\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li><a href=\"https:\/\/console.developers.google.com\/project?hl=ja\" title=\"Google Developers Console\" target=\"_blank\">Google Developers Console<\/a>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066Google \u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u30b5\u30a4\u30f3\u30a4\u30f3\u3057\u307e\u3059\u3002<\/li>\n<li>\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210<\/span>\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u65b0\u3057\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059(\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u306f\u9069\u5f53)\u3002<\/li>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_02.png\" alt=\"GmailAPI_01_02\" width=\"414\" height=\"276\" class=\"alignnone size-full wp-image-4526\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_02.png 414w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_02-300x200.png 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_02-220x146.png 220w\" sizes=\"auto, (max-width: 414px) 100vw, 414px\" \/><\/a><\/p>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_03.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_03.png\" alt=\"GmailAPI_01_03\" width=\"544\" height=\"470\" class=\"alignnone size-full wp-image-4527\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_03.png 544w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_03-300x259.png 300w\" sizes=\"auto, (max-width: 544px) 100vw, 544px\" \/><\/a><\/p>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_04.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_04.png\" alt=\"GmailAPI_01_04\" width=\"510\" height=\"131\" class=\"alignnone size-full wp-image-4528\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_04.png 510w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_04-300x77.png 300w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/a><\/p>\n<li>API\u753b\u9762\u304b\u3089\u300c<span style=\"color: #ff0000; font-weight: bold;\">Gmail API<\/span>\u300d\u3092\u6709\u52b9\u306b\u3057\u307e\u3059\u3002<\/li>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_05.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_05.png\" alt=\"GmailAPI_01_05\" width=\"809\" height=\"587\" class=\"alignnone size-full wp-image-4529\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_05.png 809w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_05-300x217.png 300w\" sizes=\"auto, (max-width: 809px) 100vw, 809px\" \/><\/a><\/p>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_06.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_06.png\" alt=\"GmailAPI_01_06\" width=\"809\" height=\"587\" class=\"alignnone size-full wp-image-4530\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_06.png 809w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_06-300x217.png 300w\" sizes=\"auto, (max-width: 809px) 100vw, 809px\" \/><\/a><\/p>\n<li>\u8a8d\u8a3c\u60c5\u5831\u753b\u9762\u304b\u3089\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u65b0\u3057\u3044\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u3092\u4f5c\u6210<\/span>\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/li>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_07.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_07.png\" alt=\"GmailAPI_01_07\" width=\"452\" height=\"284\" class=\"alignnone size-full wp-image-4531\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_07.png 452w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_07-300x188.png 300w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/a><\/p>\n<li>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7a2e\u985e\u306f\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/span>\u300d\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7a2e\u985e\u306f\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u305d\u306e\u4ed6<\/span>\u300d\u3092\u9078\u629e\u3057\u3001\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u3092\u4f5c\u6210<\/span>\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/li>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_08.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_08.png\" alt=\"GmailAPI_01_08\" width=\"540\" height=\"465\" class=\"alignnone size-full wp-image-4532\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_08.png 540w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_08-300x258.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/a><\/p>\n<li>\u30cd\u30a4\u30c6\u30a3\u30d6 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4f5c\u6210\u3055\u308c\u305f\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID<\/span>\u300d\u3001\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30b7\u30fc\u30af\u30ec\u30c3\u30c8<\/span>\u300d\u3001\u300c<span style=\"color: #ff0000; font-weight: bold;\">\u30ea\u30c0\u30a4\u30ec\u30af\u30c8 URI<\/span>\u300d\u3092\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u306b\u3067\u3082\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/li>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_09.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_09.png\" alt=\"GmailAPI_01_09\" width=\"706\" height=\"225\" class=\"alignnone size-full wp-image-4533\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_09.png 706w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_09-300x95.png 300w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/a>\n<\/ol>\n<p>\u4ee5\u4e0a\u3067\u4e0b\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<h4>\u25a0 VBA\u30b3\u30fc\u30c9<\/h4>\n<p><span style=\"color: #ff0000; font-weight: bold;\">2014\/07\/01 \u8ffd\u8a18\uff1a<\/span><br \/>\n\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\uff0664\u30d3\u30c3\u30c8\u7248Office\u306b\u5bfe\u5fdc\u3057\u305f\u30b3\u30fc\u30c9\u3082\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u30fbGmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(3)<\/strong><br \/>\n<a href=\"\/\/www.ka-net.org\/blog\/?p=4545\" title=\"Gmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(3)\" target=\"_blank\">\/\/www.ka-net.org\/blog\/?p=4545<\/a><\/p>\n<p>\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u30de\u30af\u30ed\u304c\u4e0b\u8a18\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n(\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3084\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u306f\u81ea\u5206\u306e\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002)<\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b \u4e0b\u8a18\u30b3\u30fc\u30c9\u306fScript Control\u3092\u4f7f\u3063\u3066\u3044\u308b\u305f\u3081\u300164\u30d3\u30c3\u30c8\u7248Office\u3067\u306f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\n'--------------------------------------------------\r\n'\u203b \u8981\u5909\u66f4\r\n'--------------------------------------------------\r\nPrivate Const email As String = &quot;(G\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9(\u30a2\u30ab\u30a6\u30f3\u30c8ID))&quot;\r\nPrivate Const passwd As String = &quot;(Google \u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30d1\u30b9\u30ef\u30fc\u30c9)&quot;\r\nPrivate Const client_id As String = &quot;(\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID)&quot;\r\nPrivate Const client_secret As String = &quot;(\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30b7\u30fc\u30af\u30ec\u30c3\u30c8)&quot;\r\n'--------------------------------------------------\r\n\r\nPrivate Const response_type As String = &quot;code&quot;\r\nPrivate Const redirect_uri As String = &quot;urn:ietf:wg:oauth:2.0:oob&quot;\r\n'Private Const scope As String = &quot;https:\/\/mail.google.com\/&quot;\r\nPrivate Const scope As String = &quot;https:\/\/www.googleapis.com\/auth\/gmail.compose&quot;\r\nPrivate Const grant_type As String = &quot;authorization_code&quot;\r\n\r\nPublic Sub Sample()\r\n  SendGmail email, &quot;(\u9001\u4fe1\u5148\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9)&quot;, &quot;Sample Mail&quot;, &quot;Hello.&quot; &amp; vbCrLf &amp; &quot;kinuasa.&quot;\r\nEnd Sub\r\n\r\nPrivate Sub SendGmail(ByVal MailFrom As String, _\r\n                      ByVal MailTo As String, _\r\n                      ByVal MailSubject As String, _\r\n                      ByVal MailBody As String)\r\n'Gmail API v1\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\r\n  Dim access_token As String\r\n  Dim mail_dat As String\r\n  Dim raw_dat As String\r\n  Dim dat As Variant\r\n  \r\n  access_token = GetAccessToken\r\n  If Len(Trim(access_token)) &gt; 0 Then\r\n    mail_dat = &quot;From: &quot; &amp; MailFrom &amp; vbCrLf &amp; _\r\n               &quot;To: &quot; &amp; MailTo &amp; vbCrLf &amp; _\r\n               &quot;Subject: &quot; &amp; MailSubject &amp; vbCrLf &amp; vbCrLf &amp; _\r\n               MailBody\r\n    raw_dat = EncodeBase64Str(mail_dat)\r\n    dat = &quot;{&quot;&quot;raw&quot;&quot;: &quot;&quot;&quot; &amp; DelBreak(raw_dat) &amp; &quot;&quot;&quot;}&quot;\r\n    With CreateObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)\r\n      .Open &quot;POST&quot;, &quot;https:\/\/www.googleapis.com\/gmail\/v1\/users\/me\/messages\/send&quot;\r\n      .SetRequestHeader &quot;Content-Type&quot;, &quot;application\/json; charset=UTF-8&quot;\r\n      .SetRequestHeader &quot;Authorization&quot;, &quot;Bearer &quot; &amp; access_token\r\n      .Send dat\r\n      Select Case .Status\r\n        Case 200\r\n          MsgBox &quot;\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u307e\u3057\u305f\u3002&quot;, vbInformation + vbSystemModal\r\n        Case Else\r\n          MsgBox &quot;\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002&quot; &amp; vbCrLf &amp; vbCrLf &amp; .responseText, vbCritical + vbSystemModal\r\n      End Select\r\n    End With\r\n  End If\r\nEnd Sub\r\n\r\nPrivate Sub WaitIE(ByRef IEObj As Object)\r\n'\u8868\u793a\u5f85\u3061\r\n  Const READYSTATE_COMPLETE = 4\r\n  While IEObj.Busy Or IEObj.readyState &lt;&gt; READYSTATE_COMPLETE\r\n    DoEvents\r\n  Wend\r\nEnd Sub\r\n\r\nPrivate Function GetAuthorizationCode() As String\r\n'Authorization code\u53d6\u5f97\r\n  Dim ie As Object\r\n  Dim url As String\r\n  Dim iptEmail As Object\r\n  Dim iptPasswd As Object\r\n  Dim iptSignIn As Object\r\n  Dim iptCode As Object\r\n  Dim btnApprove As Object\r\n  Dim auth_code As String\r\n  \r\n  '\u521d\u671f\u5316\r\n  Set iptEmail = Nothing\r\n  Set iptPasswd = Nothing\r\n  Set iptSignIn = Nothing\r\n  Set iptCode = Nothing\r\n  Set btnApprove = Nothing\r\n  auth_code = &quot;&quot;\r\n  \r\n  url = &quot;https:\/\/accounts.google.com\/o\/oauth2\/auth?&quot; &amp; _\r\n        &quot;client_id=&quot; &amp; client_id &amp; &quot;&amp;&quot; &amp; _\r\n        &quot;response_type=&quot; &amp; response_type &amp; &quot;&amp;&quot; &amp; _\r\n        &quot;redirect_uri=&quot; &amp; redirect_uri &amp; &quot;&amp;&quot; &amp; _\r\n        &quot;scope=&quot; &amp; EncodeURL(scope)\r\n  \r\n  Set ie = CreateObject(&quot;InternetExplorer.Application&quot;)\r\n  With ie\r\n    .Visible = True\r\n    .Navigate url\r\n    WaitIE ie\r\n    \r\n    '\u672a\u30ed\u30b0\u30a4\u30f3\u6642\u306e\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\r\n    If InStr(LCase(.document.Location.href), &quot;https:\/\/accounts.google.com\/servicelogin&quot;) Then\r\n      With .document\r\n        Set iptEmail = .getElementById(&quot;Email&quot;)\r\n        Set iptPasswd = .getElementById(&quot;Passwd&quot;)\r\n        Set iptSignIn = .getElementById(&quot;signIn&quot;)\r\n        If Not iptEmail Is Nothing Then iptEmail.Value = email\r\n        If Not iptPasswd Is Nothing Then iptPasswd.Value = passwd\r\n        If Not iptSignIn Is Nothing Then iptSignIn.Click\r\n      End With\r\n      WaitIE ie\r\n    End If\r\n    \r\n    '\u627f\u8a8d\u51e6\u7406\r\n    If InStr(LCase(.document.Location.href), &quot;https:\/\/accounts.google.com\/o\/oauth2\/auth&quot;) Then\r\n      With .document\r\n        Set btnApprove = .getElementById(&quot;submit_approve_access&quot;)\r\n        If Not btnApprove Is Nothing Then\r\n          While btnApprove.disabled &lt;&gt; False\r\n            DoEvents\r\n          Wend\r\n          btnApprove.Click\r\n        End If\r\n      End With\r\n      WaitIE ie\r\n    End If\r\n    \r\n    'Authorization code\u53d6\u5f97\u51e6\u7406\r\n    If InStr(LCase(.document.Location.href), &quot;https:\/\/accounts.google.com\/o\/oauth2\/approval&quot;) Then\r\n      With .document\r\n        Set iptCode = .getElementById(&quot;code&quot;)\r\n        If Not iptCode Is Nothing Then auth_code = iptCode.Value\r\n      End With\r\n      .Navigate &quot;https:\/\/accounts.google.com\/o\/logout&quot; '\u30ed\u30b0\u30a2\u30a6\u30c8\r\n      WaitIE ie\r\n    End If\r\n    .Quit\r\n  End With\r\n  GetAuthorizationCode = auth_code\r\nEnd Function\r\n\r\nPrivate Function GetAccessToken() As String\r\n'Access token\u53d6\u5f97\r\n  Dim auth_code As String\r\n  Dim json As String\r\n  Dim access_token As String\r\n  Dim dat As Variant\r\n  \r\n  access_token = &quot;&quot; '\u521d\u671f\u5316\r\n  auth_code = GetAuthorizationCode\r\n  If Len(Trim(auth_code)) &gt; 0 Then\r\n    dat = &quot;code=&quot; &amp; auth_code &amp; &quot;&amp;&quot; &amp; _\r\n          &quot;client_id=&quot; &amp; client_id &amp; &quot;&amp;&quot; &amp; _\r\n          &quot;client_secret=&quot; &amp; client_secret &amp; &quot;&amp;&quot; &amp; _\r\n          &quot;redirect_uri=&quot; &amp; redirect_uri &amp; &quot;&amp;&quot; &amp; _\r\n          &quot;grant_type=&quot; &amp; grant_type\r\n    With CreateObject(&quot;WinHttp.WinHttpRequest.5.1&quot;)\r\n      .Open &quot;POST&quot;, &quot;https:\/\/accounts.google.com\/o\/oauth2\/token&quot;\r\n      .SetRequestHeader &quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded;charset=UTF-8&quot;\r\n      .Send dat\r\n      If .Status = 200 Then\r\n        json = .responseText\r\n        If Len(Trim(json)) &gt; 0 Then\r\n          json = &quot;(&quot; &amp; .responseText &amp; &quot;)&quot;\r\n          With CreateObject(&quot;ScriptControl&quot;)\r\n            .Language = &quot;JScript&quot;\r\n            access_token = .CodeObject.eval(json).access_token\r\n          End With\r\n        End If\r\n      End If\r\n    End With\r\n  End If\r\n  GetAccessToken = access_token\r\nEnd Function\r\n\r\nPrivate Function EncodeURL(ByVal str As String) As String\r\n'URL\u30a8\u30f3\u30b3\u30fc\u30c9\r\n  With CreateObject(&quot;ScriptControl&quot;)\r\n    .Language = &quot;JScript&quot;\r\n    EncodeURL = .CodeObject.encodeURIComponent(str)\r\n  End With\r\nEnd Function\r\n\r\nPrivate Function EncodeBase64Str(ByVal str As String) As String\r\n'\u6587\u5b57\u5217\u3092Base64\u30a8\u30f3\u30b3\u30fc\u30c9\r\n  Dim ret As String\r\n  Dim d() As Byte\r\n  \r\n  Const adTypeBinary = 1\r\n  Const adTypeText = 2\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Open\r\n    .Type = adTypeText\r\n    .Charset = &quot;UTF-8&quot;\r\n    .WriteText str\r\n    .Position = 0\r\n    .Type = adTypeBinary\r\n    .Position = 3\r\n    d = .Read()\r\n    .Close\r\n  End With\r\n  With CreateObject(&quot;MSXML2.DOMDocument&quot;).createElement(&quot;base64&quot;)\r\n    .DataType = &quot;bin.base64&quot;\r\n    .nodeTypedValue = d\r\n    ret = .Text\r\n  End With\r\n  On Error GoTo 0\r\n  EncodeBase64Str = ret\r\nEnd Function\r\n\r\nPrivate Function DelBreak(ByVal str As String) As String\r\n'\u6539\u884c\u524a\u9664\r\n  Dim ret As String\r\n  \r\n  ret = &quot;&quot; '\u521d\u671f\u5316\r\n  ret = Replace(str, vbNewLine, &quot;&quot;)\r\n  ret = Replace(ret, vbCr, &quot;&quot;)\r\n  ret = Replace(ret, vbLf, &quot;&quot;)\r\n  DelBreak = ret\r\nEnd Function<\/pre>\n<p>\u4e0a\u8a18\u30de\u30af\u30ed\u306f\u627f\u8a8d\u4f5c\u696d\u306e\u81ea\u52d5\u5316\u3082\u884c\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u554f\u984c\u304c\u767a\u751f\u3057\u306a\u3051\u308c\u3070\u5b9f\u884c\u5f8c\u3059\u3050\u306b\u6307\u5b9a\u30a2\u30c9\u30ec\u30b9\u306b\u30e1\u30fc\u30eb\u304c\u9001\u4fe1\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_10.png\" alt=\"GmailAPI_01_10\" width=\"619\" height=\"394\" class=\"alignnone size-full wp-image-4534\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_10.png 619w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GmailAPI_01_10-300x190.png 300w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><\/a><\/p>\n<p>\u305f\u3060\u3001\u4e0a\u8a18\u30de\u30af\u30ed\u306fAPI\u306e\u30c6\u30b9\u30c8\u7528\u306b\u66f8\u3044\u305f\u3060\u3051\u306a\u306e\u3067\u3001\u30e1\u30fc\u30eb\u30d8\u30c3\u30c0\u306e\u8a2d\u5b9a\u3084\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u5341\u5206\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u65e5\u672c\u8a9e\u306e\u30e1\u30fc\u30eb\u3084\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u5834\u5408\u306b\u306f\u3001\u3082\u3046\u5c11\u3057\u51e6\u7406\u3092\u4ed8\u3051\u52a0\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>\u25a0 \u95a2\u9023Web\u30da\u30fc\u30b8<\/h4>\n<p><strong>\u30fbGmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(2)<\/strong><br \/>\n<a href=\"\/\/www.ka-net.org\/blog\/?p=4538\" title=\"Gmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(2)\" target=\"_blank\">\/\/www.ka-net.org\/blog\/?p=4538<\/a><br \/>\n<strong>\u30fbGmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(3)<\/strong><br \/>\n<a href=\"\/\/www.ka-net.org\/blog\/?p=4545\" title=\"Gmail API\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308bVBA\u30de\u30af\u30ed(3)\" target=\"_blank\">\/\/www.ka-net.org\/blog\/?p=4545<\/a><\/p>\n<h4>\u25a0 \u3042\u3068\u304c\u304d<\/h4>\n<p>\u3068\u308a\u3042\u3048\u305a\u4eca\u56de\u306e\u30de\u30af\u30ed\u3067VBA\u304b\u3089Gmail API\u3092\u547c\u3073\u51fa\u305b\u308b\u306e\u306f\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\n\u30b3\u30fc\u30c9\u306e\u7d30\u304b\u3044\u8aac\u660e\u3084\u30e1\u30fc\u30eb\u30d8\u30c3\u30c0\u306e\u51e6\u7406\u5b9f\u88c5\u306f\u307e\u305f\u5f8c\u65e5\u306b\u3084\u308b\u3001\u3001\u3001\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u30fb\u30fb\u30fb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300c\u300cGmail API\u300d\u03b2\u7248\u516c\u958b\u3001\u9023\u52d5\u30a2\u30d7\u30ea\u958b\u767a\u3092\u652f\u63f4\u300d\u306b\u3082\u3042\u308b\u3088\u3046\u306b\u3001\u5148\u65e5Gmail API\u304c\u3088\u3046\u3084\u304f\u516c\u958b\u3055\u308c\u307e\u3057\u305f\u3002 \u30fbGmail API &#8211; Google Developers https:\/\/deve [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49,126],"tags":[],"class_list":["post-4524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","category-google"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Excel.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1aY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4524"}],"version-history":[{"count":6,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4524\/revisions"}],"predecessor-version":[{"id":4550,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4524\/revisions\/4550"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7111"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}