<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>API key &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/api-key/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Fri, 06 Aug 2021 07:10:37 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>API key &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹</title>
		<link>https://noter.tw/8942/google-apis-3-service-account-credentials/</link>
					<comments>https://noter.tw/8942/google-apis-3-service-account-credentials/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 07:37:41 +0000</pubDate>
				<category><![CDATA[技術相關]]></category>
		<category><![CDATA[網頁後端]]></category>
		<category><![CDATA[程式開發]]></category>
		<category><![CDATA[建立 Service Account]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[APIs & Services]]></category>
		<category><![CDATA[記下來]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Google APIs]]></category>
		<category><![CDATA[Google APIs Credentials]]></category>
		<category><![CDATA[Credentials 介紹]]></category>
		<category><![CDATA[說明]]></category>
		<category><![CDATA[OAuth client ID]]></category>
		<category><![CDATA[API key]]></category>
		<category><![CDATA[Service account]]></category>
		<category><![CDATA[教學]]></category>
		<category><![CDATA[Google 認證]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=8942</guid>

					<description><![CDATA[<p>總算沒偷懶已經來到第三篇了，還不清楚怎麼回事的朋友可以看前面兩篇 PHP Client 操作 Google APIs (1) 開啟與測試 API 及 PHP Client 操作 Google APIs&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/8942/google-apis-3-service-account-credentials/" data-wpel-link="internal">PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>總算沒偷懶已經來到第三篇了，還不清楚怎麼回事的朋友可以看前面兩篇 <a style="font-size: revert;" rel="noreferrer noopener" href="https://noter.tw/8940/google-apis-1/" target="_blank" data-wpel-link="internal">PHP Client 操作 Google APIs (1) 開啟與測試 API</a> 及 <a style="font-size: revert;" rel="noreferrer noopener" href="https://noter.tw/8944/google-apis-2/" target="_blank" data-wpel-link="internal">PHP Client 操作 Google APIs (2) 安裝 Google API Client for PHP</a>，這篇記錄如何建立 Google APIs Credentials 進行認證，並說明各認證方式的差別。</p>



<span id="more-8942"></span>



<p class="withcode">這系列小蛙以 Google Search Console API 當作例子，其他的 Google APIs 大致上使用的流程類似，差別可能在於用到的物件不同 (Google 分析就要改成使用 <code>Google_Service_Analytics</code> 物件)、要設定的 Scope 不同 (<code>Google_Service_Analytics::ANALYTICS_READONLY</code>，這些在 Google APIs 文件上都會有)，可以使用的認證方式不同 (有的限定只能 OAuth) 等等。</p>



<h2 class="para wp-block-heading">認證方式 (Google APIs Credentials)</h2>



<p class="withcode pink-solid">Google 在 <a href="https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">API Console<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 裡提供了 3 種認證方式，分別是：<code>API Key</code>、<code>OAuth client ID</code> 及 <code>Service account</code>。如果不清楚該使用哪一種的話，可以點最下面的 Help me choose。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWsr_HcF9xUg_K2uLOc0AIx60-NcmcdxJCRRuW8QHXPQTEheM7Ct1EEhDMCbhmmiAAbaMAOnIGqfSOea6Y2wlJt7avO-8tLs6B3er1BJlO5z5IcZhlknQeIAZXTnmUegsn7zlimWzmNVJnDLT8KW0yHwA=w448-h282-no?authuser=3" alt="Google APIs Credentials" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<h3 class="para wp-block-heading">API Key</h3>



<p>API Key 是最簡單也最單純的，如果使用到 Google APIs 的功能是支援 API Key 存取的話，這是一個非常簡單的好選項，只要設定完成後，會得到一組 API Key，接著設定在 API Client 內就可以使用了。</p>



<h3 class="para wp-block-heading">OAuth client ID</h3>



<p>透過自己的 Gmail 帳號登入後並授權後才可以使用，用來存取自己帳號相關的資料，例如：行事曆、Search Console 資料、Google Analytics 資料 &#8230; 等。第一篇測試 APIs Explorer 時跳出的視窗就是使用 OAuth 2.0 登入的畫面。</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLViqpex5Vq1tiC-5zHF84HkfewOulCuvoms8WvDbmNC4WNlWfxr_sW0PPedt4Mu8xhel_4oidPPm9R2hXS72UjvzhglZyQkLW6Bxwets6MXnrEZDseuzGfqeJGoHbzMTB8bGlqWvCzMQrJUotyxb5P4Fg=w601-h660-no?authuser=3" alt="OAuth 2.0 Login Screen" width="451" height="495" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<h3 class="para wp-block-heading">Service account</h3>



<p>主要在 Server 端的應用，有些 APIs 需要透過 OAuth 取得帳號相關資料，但是如果要讓它自動執行或是做成機器人 (robot) 的話，沒辦法每次跳出視窗讓你去按登入授權，因此這種狀況選擇 Service account 就對了。</p>



<h2 class="para wp-block-heading">建立 Service Account </h2>



<p>繼續到 GCP 左側選單，點擊 APIs &amp; Services -&gt; Credentials</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLVwRX1gGcTjFQpwDX1KvCbZGYS1ZuoR21ueYlqk2HL6NoqldMtZEF6EccUjnWQq4S7gRIQdV2Me8A0AGDIOnTwlUmBvymjHDai5_Wki8njdr-FeL-8iwFtWR5GnhJ-VcO2FW9RzdUBgQbEfkyFi8DrsxQ=w452-h508-no?authuser=3" alt="Google APIs Credentials 1" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>點擊上方 CREATE CREDENTIALS 後選擇 Service account</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWsr_HcF9xUg_K2uLOc0AIx60-NcmcdxJCRRuW8QHXPQTEheM7Ct1EEhDMCbhmmiAAbaMAOnIGqfSOea6Y2wlJt7avO-8tLs6B3er1BJlO5z5IcZhlknQeIAZXTnmUegsn7zlimWzmNVJnDLT8KW0yHwA=w448-h282-no?authuser=3" alt="Google APIs Credentials 2" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>輸入帳號名稱 (Service account name) 後會自動產生 (Service account ID)，輸入描述避免太多 Credentials 的時候可以弄清楚哪個是哪個，輸入完成後點擊 CREATE AND CONTINUE</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWPU0h72ZGCeUnCbvMw5BR9nzGpOVZNZk4hQb8HvNr_ch_quwpujdXI0EigqkXMLDEPe3RsOtocWpxk5UJLiNGcamxDjVoJpIW4NuS_ihuV14IyFoJ81n9KTYh5jCAwWZYANJbEKXzRg69BViOjj2CBbw=w540-h430-no?authuser=3" alt="Google APIs Credentials 3" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>這步驟是選用的，小蛙直接跳過</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLUtquEXwP7kq6E9-rw9Xm0c6q--rr8vhNmyOCDmRNUppTPV6oWsS_swrgUtqSVkRF_hVzvkIQLKvCzf2rct__mlHvYA0uxnbWowWoN6pKsteIPv5KAqhgN_Ti-3ZHqqEbZ04ICSh5AAl1MiymmxdZ61Ng=w523-h363-no?authuser=3" alt="Google APIs Credentials 4" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>這步驟也是選用的，直接跳過</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLX_uiCo_D0ASkeoSQO5zEM3K4_Y5BXmgxxONvPiGeKcT9Vb7GuzWNm8legvtzE6uVTgUt_BR-L6CgKMvIoUpQsqSYXK8QlvMULhqIkCSr1kSn96-Wnx-utTx3Gy6UE7DHvkNmOLfxiTiqphM-DKvrMwGQ=w527-h317-no?authuser=3" alt="Google APIs Credentials 5" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>回到主畫面後可以看到剛剛新增的帳號出現了，點選右邊的鉛筆進入修改畫面</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLU_OhP-_kwBeNqHbmhuo0Dn0uK_yH_ARM1RnSV3j1Ai2wJaCFfwRxWcnGFfdFoYsvyEV3dkxU_Fx3UA57Kt2Kgrhq8qW6YpniaDCFHfdaIMXM38Z8vSbFdwrlkDT2MUPV44j-31c5KHNtKoD4mrz9zR2g=w798-h172-no?authuser=3" alt="Create Credentials 6" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>上方切換到 KEYS 頁籤 (1)，點擊下方 ADD KEY (2)，選擇 Create new key (3)</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWS7pdvaQdNoJdCL4vHP1EBApz1KUFuhKUu9UF02boWTzM7l-NJbcKo0xy_P_DRUpk5tKulBfpqF7c96nfMWNt7gdzmZCsCyAe8WSOfkV2HPD0n8NX6CXSmNneQsZIK8DDlj61Cy0bveB3POdOsWAnbRg=w488-h460-no?authuser=3" alt="Create Credentials 7" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>選擇 Key type，Google 建議使用 JSON 格式 (1) 的就好，點擊右下角的 CREATE (2)</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLV-HbT8k_2SZOSa_lWjr-tFn9n4e6oQEK4R1u_xZw36u-Cm8XxxNrB1o9fN0_jawmUByCaTkOn-rnpemUIXG8xYVoBptRx0sL5Qd_YD03Qrf-TqrFngKejWBxzL7VBnn2O87QXoThjAWmIzFXdIvXHCgw=w530-h328-no?authuser=3" alt="Create Credentials 8" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>接著會開始下載 JSON，這個 JSON 一定要保存好喔，如果遺失了是沒辦法再下載的，只能把原本的刪除後再產生一個，一定要注意。</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLVto-2A2QceFHDryLAVFYIBxDiI8exjglSIhl03n8v7qDynqYwM1q6x0NHsrnVhPaawZ3W7AKdGSdiCchb_RBgVFZZMbQe_GKcfso0Cjz7yTuaFGDJmlrlRARv3u_xKx_yk5u-Sq1ckoKq5UpQ1OlHCkQ=w677-h131-no?authuser=3" alt="Create Credentials 9" title="PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹"></figure></div>



<p>到這邊 Service Account 就建立完成了，下一篇將會說明如何透過 PHP Client 操作 Google Search Console APIs 來取得相關數據。</p>



<p id="block-c58a739f-b4e1-42ae-8530-5e20da347253"><strong>Google 系列文章：</strong></p>



<ul class="wp-block-list" id="block-2b1f3c8f-95c7-4eff-8105-53dea9d75e5e"><li><a href="https://noter.tw/8940/google-apis-1-api-explorer/" data-wpel-link="internal">PHP Client 操作 Google APIs (1) 開啟與測試 API</a></li><li><a href="https://noter.tw/8944/google-apis-2-google-api-client-for-php/" data-wpel-link="internal">PHP Client 操作 Google APIs (2) 安裝 Google API Client for PHP</a></li><li><a href="https://noter.tw/8942/google-apis-3-service-account-credentials/" data-wpel-link="internal">PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹</a></li><li><a href="https://noter.tw/9035/google-apis-4-google-search-console-apis/" data-wpel-link="internal">PHP Client 操作 Google APIs (4) 使用 Google Search Console APIs</a></li><li><a href="https://noter.tw/8604/google-formranger/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Google 表單應用：設定選項次數上限</a></li><li><a href="https://noter.tw/9049/copy-a-google-form/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">複製 Google 表單 (Copy A Google Form)</a></li><li><a href="https://noter.tw/8358/google-adsense-tax-w8ben/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Google Adsense: 向 Google 提交稅務資料 | 填寫 W-8BEN 稅務表單</a></li><li><a href="https://noter.tw/4946/google-%e9%9b%b2%e7%ab%af%e5%a4%96%e5%b8%b6%e6%9c%8d%e5%8b%99-takeout%ef%bc%9a%e8%bc%95%e9%ac%86%e6%89%93%e5%8c%85%e9%9b%b2%e7%ab%af%e7%a1%ac%e7%a2%9f%e3%80%81%e7%9b%b8%e7%b0%bf-%e7%ad%89/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Google 雲端外帶服務 (Takeout)：輕鬆打包雲端硬碟、相簿 … 等資料</a></li><li><a href="https://noter.tw/4394/google-%e7%9b%b8%e7%b0%bf%e5%8f%96%e5%be%97%e7%9c%9f%e5%af%a6%e5%9c%96%e7%89%87%e4%bd%8d%e7%bd%ae%ef%bc%88%e6%8f%92%e5%85%a5%e5%9c%96%e7%89%87%e5%88%b0%e6%96%87%e7%ab%a0%ef%bc%89/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Google 相簿取得真實圖片位置（插入圖片到文章）</a></li><li><a href="https://noter.tw/4267/gdirve-%e8%ae%93%e4%bd%a0%e5%9c%a8-linux-%e6%96%87%e5%ad%97%e4%bb%8b%e9%9d%a2%e4%b9%9f%e8%83%bd%e5%a5%bd%e5%a5%bd%e4%bd%bf%e7%94%a8-google-drive/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">gdirve 讓你在 Linux 文字介面也能好好使用 Google Drive</a></li><li><a href="https://noter.tw/4302/microsoft-office-word-%e7%84%a1%e6%b3%95%e9%96%8b%e5%95%9f-google-drive-%e8%b6%85%e9%80%a3%e7%b5%90/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">Microsoft Office Word 無法開啟 Google Drive 超連結</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/8942/google-apis-3-service-account-credentials/" data-wpel-link="internal">PHP Client 操作 Google APIs (3) Google APIs Credentials 介紹</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/8942/google-apis-3-service-account-credentials/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
