<?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 Console &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/api-console/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Sun, 27 Jul 2025 03:16:28 +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 Console &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>gdrive3 : Google Drive CLI Client</title>
		<link>https://noter.tw/12951/gdrive3-google-drive-cli-client/</link>
					<comments>https://noter.tw/12951/gdrive3-google-drive-cli-client/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 27 Jul 2025 03:14:56 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技巧分享]]></category>
		<category><![CDATA[文字介面 Google Drive 工具]]></category>
		<category><![CDATA[Google Drive]]></category>
		<category><![CDATA[自動化流程]]></category>
		<category><![CDATA[gdrive]]></category>
		<category><![CDATA[新增資料存取權]]></category>
		<category><![CDATA[API Console]]></category>
		<category><![CDATA[gdrive3]]></category>
		<category><![CDATA[Google Drive API]]></category>
		<category><![CDATA[Google Drive CLI]]></category>
		<category><![CDATA[啟用 Google Drive API]]></category>
		<category><![CDATA[設定 Oauth 同意畫面]]></category>
		<category><![CDATA[啟用 API]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=12951</guid>

					<description><![CDATA[<p>小蛙照著之前 gdirve 讓你在 Linux 文字介面也能好好使用 Google Drive 來設定新機器使用 gdrive，結果發現在 gdrive about 要進行授權時一直顯示被 block&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/12951/gdrive3-google-drive-cli-client/" data-wpel-link="internal">gdrive3 : Google Drive CLI Client</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙照著之前 <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> 來設定新機器使用 gdrive，結果發現在 gdrive about 要進行授權時一直顯示被 block 無法使用，查了之後才發現 gdrive 已經更新到 gdrive3 了，舊的方法已經沒辦法正常使用，這篇文章記錄如何使用 gdrive3: Google Drive CLI Client，透過文字命令列使用的 Google Drive 工具。</p>



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



<p>gdrive3 要設定的部分比較多也比較麻煩，不像前一版只要下載回來，<code>gdrive about</code>授權完成就可以了，跟著小蛙來一步一步設定吧。</p>



<h2 class="wp-block-heading para">下載 gdrive 套件</h2>



<p><a href="https://github.com/glotlabs/gdrive" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">gdrive3 套件連結下載<span class="wpel-icon wpel-image wpel-icon-6"></span></a>。</p>



<p>點進去之後找到 <a href="https://github.com/glotlabs/gdrive/releases" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">the release section<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，小蛙寫這篇文章的時候最新版本是 3.9.1，下載對應自己作業系統的版本</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNYGCVrMPw553P6PmskDplhKBzRY79R8oRxpZDvvq_HgWCE0ZFBBWL_zCxXg_kAKBwIIzqLjeHGSeWYVP5qcO1v5Uwcke_LlawDMwPdOtCOY-HG72LY-V4AtnELjDGR-OR7iE-R6RCYU8gfyMm7tmgz=w602-h398-rw" alt="gdrive3 : Google Drive CLI Client - 下載 gdrive3 套件" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>在 shell 環境中下，下載 gdrive、解壓縮，並移動到 <code>/usr/sbin/</code> 讓他可以全域執行</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">wget https://github.com/glotlabs/gdrive/releases/download/3.9.1/gdrive_linux-x64.tar.gz
tar -xzvf gdrive_linux-x64.tar.gz
mv ./gdrive /usr/sbin/</pre>



<h2 class="wp-block-heading para">設定 Google 帳號授權</h2>



<p>這版本的 Google 授權跟上一版比較起來真的超級麻煩，github 主頁上也有完整且詳細授權教學 <a href="https://github.com/glotlabs/gdrive/blob/main/docs/create_google_api_credentials.md" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Create Google API credentials in 50 easy steps<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，有 50 個步驟看起來真的是超級麻煩 &#8230; 不過點進去看的話就會發現其實不到 50 個步驟啦！大約只有 28 個 (&#8230;. 還是很多啊！！！)</p>



<h3 class="wp-block-heading para">建立 Google Cloud 專案</h3>



<p>首先<a href="https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">進入到 Google Clound 控制台<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，第一次使用的話點擊左上角「選取專案」，然後「新增專案」，如果原本就有專案存在的話，使用既有的專案也可以。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczP0fl0a86H4MfeOh6GaZ5ERMdRMF83rk5qz0agX-X8pcif-TXzCQPb5vmg7hr13tUoKQzSY80hzROQQ4649mWRQCb8WKwffZWKxB61IrVqyaxnkljW9AFAhR7oFEU00evNotLxQfsZKiOkQvZL69foP=w841-h260-rw" alt="gdrive3 : Google Drive CLI Client - Google Cloud 建立專案 1" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>輸入可以辨識的專案名稱，點擊建立，建立完成後右上角會跳出通知，點擊選取專案進入專案頁面</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNrnf_bFPLl5E4QeJGkkdN1RCm1Eyux0e8lfr44oUZ4Bt77KFuWR4KlRsaSyAs4qrYkj7pdOR4biuoOfwXajiLu9f48VvMhSWfx2r3LpCfgH560WU5jEBQ7iU6GZETL3FCivNolSKUJLc9UVIG_CsSB=w551-h399-rw" alt="gdrive3 : Google Drive CLI Client - Google Cloud 建立專案 2" title="gdrive3 : Google Drive CLI Client"></figure></div></div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNAiS6uv8WDQfVv8dnILSXKRhmtnOhOq5w8Qo7WOTrdhQNgxvVWvJ8PXCoOgLRzr59zNCZHtkWjOO0UJAGeJyqRRrWAdTXJGE28vi0cBO0kqKK-7RvQGkXNiVZX64X3StL4zL11zWHrmWa862Mr_bH7=w410-h179-rw" alt="gdrive3 : Google Drive CLI Client - Google Cloud 建立專案 3" title="gdrive3 : Google Drive CLI Client"></figure></div></div>
</div>



<h3 class="wp-block-heading para">啟用 Google Drive API</h3>



<p>在上方搜尋欄輸入「drive api」，點擊第一個搜尋結果「Google Drive API」，點擊「啟用」來使用 Google Drive API</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-2 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOqLBQSVz3N2daUjVJsa0ltc0KdImgBST5T93F_rMZY_efzNxOY-7r08u7J6A4ZJbBwoR6-JTIryfBthoOFtfUQizbaCOf5XJoZ3E_x_yQSBlZhFAoTIYGK8GujLohiuJrW7VoCV5HHcGa828qzTXt4=w416-h278-rw" alt="gdrive3 : Google Drive CLI Client - 啟用 Google Drive API 1" title="gdrive3 : Google Drive CLI Client"></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMVGVUfhMRdh17XNe_UlMGU3Csrsmh0tFdhmpzvbCV4smmqCvpCSgb6leFmnxdx-k92AXGByCIu7F1byeNRQtZ2XTZRA6gXOq5u3MarP5Cco7nCGCcfUwHD_JD9cINosoag_wJgJ1Vy3nYY2tdouK5-=w455-h217-rw" alt="gdrive3 : Google Drive CLI Client - 啟用 Google Drive API 2" title="gdrive3 : Google Drive CLI Client"></figure>
</div>
</div>



<h3 class="wp-block-heading para">設定 OAuth 同意畫面</h3>



<p>成功啟用 Google Drive API 後，點擊左側選單「憑證」，點擊「設定同意畫面」</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczM8VZJ2vkRhb6YpzcHJ3o3d2MwaTFiGO75nD2EQMsmURNcmhU_v34nDyGtQ6dq1041vrDMdFaErp7HpMvRSTG7blXxm1X-_g7Bp-qLsbdxLnl1UXCDXtgEyItOIuQ5L9mQ9e-B51hWIzTqRoebbMo7H=w954-h346-rw" alt="gdrive3 : Google Drive CLI Client - 設定 OAuth 同意畫面 1" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>點擊「開始」設定 Google 驗證平台，輸入應用程式名稱及使用者支援電子郵件</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-3 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOYSM6asBcoMrW-0o15VZ8PVp5ze5NjZQeiMD8iDMf_8w9xWghjnhcciIPGihLjOOWtPuabPEo4ozjUM4gNjzgWpd59wNwtrdtjl5EofedlrdAkupr3ZOP75ro-wEZWAtnpCC1Lcg4vOGQzp8c-MXiq=w542-h445-rw" alt="gdrive3 : Google Drive CLI Client - 設定 OAuth 同意畫面 2" title="gdrive3 : Google Drive CLI Client"></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNoQt-RvfeX5GloxfFnfXx7Mb3dytWCZlEz83Abf3RdQ4vMVqYKXvqXMt7I4RwIxjuJOu8pr0Tkt2aBzqQYLGfoLxwWWmQYf3wn-gBO28OrZksck30ByOgJRH-K-3gTGbW68Z7Y8NeyPzaMDQ1IrsjO=w576-h355-rw" alt="gdrive3 : Google Drive CLI Client - 設定 OAuth 同意畫面 3" title="gdrive3 : Google Drive CLI Client"></figure>
</div>
</div>



<p>目標對象選擇「外部」，填入聯絡資訊，同意條款後點擊「建立」</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-5 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNLR_1S9o3ED6tFNo6Su6a9S3UzvMkHFuAoc1HrMApZB2GuenHAZHyHxEIrKuCv82I7zsfEvfEJYfaGKMedSW_46xR27ooNqGv8dIDjM3MJCUiV8z5InbVxQNwPLyjzEaD2bB29UJRt7sGuNV_9iPzM=w565-h393-rw" alt="gdrive3 : Google Drive CLI Client - 設定 OAuth 同意畫面 4" title="gdrive3 : Google Drive CLI Client"></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-4 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczN-irV9NqSHPOXvVWQAJRTxBEtkfeqYVzmDQ6G7Va95Iw8zEtioK4WFoTxEgeJM4NgYOq3JEMkB03LR5QjU1zHy35OIx8kJatocgjwo8kvunm3LzI0pfK_7JXJCJ6gGJikMPDK7f-NVvSqng1nT_Fe8=w613-h329-rw" alt="gdrive3 : Google Drive CLI Client - 設定 OAuth 同意畫面 5" title="gdrive3 : Google Drive CLI Client"></figure>
</div>
</div>
</div>
</div>



<h3 class="wp-block-heading para">新增資料存取權</h3>



<p>點擊「資料存取權」-&gt;「新增或移除範圍」</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczPvSO-Epve8DVslM0S9SUx-zOZd8GDrolC6UhRNp1owEtyTjk56MWqmfPeoTiI8c00_Ns5fhYPqFjCsURsXtQWfbvxKD14W46Xk00vYTeFqeLTvxI_0dwadhsr6MdqTu9eaZrCCOhm-XyfngiUFjnw9=w792-h348-rw" alt="gdrive3 : Google Drive CLI Client - 新增資料存取權 1" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>篩選條件輸入「Google Drive API」，下方範圍選擇 <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color"><strong>&#8230;/auth/drive</strong></mark> 及 <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color"><strong>&#8230;/auth/drive.metadata.readonly</strong></mark> 兩個，選完後點擊最下方「更新」</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMzKE-BM9NyW0cUpgeD8iMNxPjEPvI6bG_0O4dyQhvINp6TIuVSlzv1fj3QxKNMacNPp7tlfXxZlldGLtkv28uxQlLZh-P5WnqIC9RBImcEdBMseTOY7vv_9KkeJdli3x6YoWuQv_aWBc1LplgpzKlh=w725-h635-rw" alt="gdrive3 : Google Drive CLI Client - 新增資料存取權 2" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>接著畫面會顯示剛剛選擇的那兩個，點擊 Save 儲存</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMqS5L81SnhDeBo_9FpoKQRnAF4wtuchykCW92Oiv-fnVgQUJmNnCBXxpgBS2ZUL2fU8yXoX-saKHQUUxHVj_liw9bH8dlGdgJ62WLFp-xiQG6DysPA0bDHLb3EeI401mu9KHj9NmQhXv4uqOvp5O2s=w537-h372-rw" alt="gdrive3 : Google Drive CLI Client - 新增資料存取權 3" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h3 class="wp-block-heading para">新增目標對象</h3>



<p>接著點擊「目標對象」-&gt;「Add users」</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczN5LlpqroLq6SMmPnlxVGtBr1sk9gQymiaqhWGuXGC6Z-pLq1h2F-kxdnqZq6c2fIce71tLcG6fWCp085d4xb1CHWVu9rqLh-mxQm4cuTCIsb_l26U1KdnoCVpSATg0mVkR8omqF18YiMkKRnFeltPT=w865-h686-rw" alt="gdrive3 : Google Drive CLI Client - 新增目標對象 1" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>輸入要使用 gdrive3 的使用者</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNuqBAtgoT82GQc23Fyw81Tab3aiG2rDSKOoRa3y8j_TH9i08nh2BYD6EbwGKQTCJ6gYPSYKEjn_YKFBcLRLzL2TOPz95T9lKKmGDN09vOvvKgHoU1j6nWgEZ-9mfTjzQfZr3g6D7oWKnqKms8TsBel=w735-h320-rw" alt="gdrive3 : Google Drive CLI Client - 新增目標對象 2" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h3 class="wp-block-heading para">建立 Oauth 用戶端</h3>



<p>點擊「用戶端」-&gt;「建立用戶端」，應用程式類型選擇「電腦版應用程式」，接著輸入自己可以辨認的名稱即可</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-6 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOMvrV0LjbXZBK7jRy8zmev1fVORHPKsS2nimuyDXT3Cevva6S0pWuV_jmQrcIXfcKROeDTsYREvouRtozdh8OO9nSk4kKRSJ59LhBKjMjvTgdWI3lBy1KKXiBXPGFsy1-g5Va_p2HyZ4_q1uXRvBgY=w585-h305-rw" alt="gdrive3 : Google Drive CLI Client - 建立 Oauth 用戶端 1" title="gdrive3 : Google Drive CLI Client"></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczPQgzwcgrd_GP09lwKTxd81OQTYB1FG6mK_IUqGUXKM68YQQJALdsHjCxH9LUUgBsXj-bAdU9N4M99TrF2wIbw9W8sQ-zk0HWa0JJgA52CYGjrWqp0FSc0oy_XRq0VrSN5rY3ukJeISAhf4MMJ3JFvS=w555-h410-rw" alt="gdrive3 : Google Drive CLI Client - 建立 Oauth 用戶端 2" title="gdrive3 : Google Drive CLI Client"></figure>
</div>
</div>



<p>建立完成，點擊「下載 JSON」可以把密鑰下載下來，要注意這邊的密碼要記起來，關閉這視窗之後就再也看不到這個密碼了，只能刪除重建一個新的喔。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczP50ROlmnjFVVtV8-IOKQw3phcLk8IpM-4F-XP55K3stWTDsFr3V7_5zT9K2MiPM7mCoSwqLONiXQDsBPrhmKEUFcW1ocQVM4waxNPfDUU00MO_MC_yYmj6ES3pkyZGO-9ZZGJK3DcdPRt1ApWMBf0p=w503-h512-rw" alt="gdrive3 : Google Drive CLI Client - 建立 Oauth 用戶端 3" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h3 class="wp-block-heading para">發布應用程式</h3>



<p>點擊左側「目標對象」->「發布應用程式」</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOm8jL9_IeXoDK7dURzsWYm5zJsG4uqBuxv_uyshbAI-86TfdMB5CJqCTEkvKP6pGSEy3AfsWpIpUaOiau63P4QP8eXPtoqlm4a0F0KUaJlbHF0apJrUNERNjV6USrPdCIm1qyNHH5Icx2GHvQtKPKe=w435-h303-rw" alt="gdrive3 : Google Drive CLI Client - 發布應用程式 1" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>確認後就完成 Google Drive API 的設定囉 ~</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMusqFYBxlEMnD5aOEpuLl9Y4wDdiWYSjHG2HclKyo2BapTcg1UehDRszGdF60wbhkTdjt0VQQAuHF6gK_wrgo41EFis7_0uIu-vSInWl0RPP8S8MeiFEDxxYlbp8NSQbkYvn998XzWt3QHUHqAsDoP=w549-h207-rw" alt="gdrive3 : Google Drive CLI Client - 發布應用程式 2" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h2 class="wp-block-heading para">gdrive3 認證</h2>



<p>這部分要依照「本機是否可以開啟瀏覽器」來區分，因為小蛙安裝在 VPS 上沒有辦法開啟瀏覽器來驗證，也不像前一版可以遠端驗證</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOpkuwA4LWDNYEi_vCS2d6__w4A1bKlHe5C4JIaLYSip2dqKlb4zpkKUiHfBxgNtnTJW2M63H5TVcdx47rdjPAHHigBHeHQficR8MH2BrKE4NpWPiNVK58E4FBRrXPo3_9-PgZLKvCx64d2cx0uzKRB=w641-h419-rw" alt="gdrive3 : Google Drive CLI Client - 認證 失敗" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>因此這邊需要在 Windows 本機也安裝 gdrive，在本機驗證成功後，把設定檔匯出，在到 VPS 上匯入設定檔，這樣就能讓不能開瀏覽器的主機也能正常使用 gdrive，下面小蛙就示範怎麼執行這些步驟。</p>



<p>下載 Windows 版本的 gdrive，解壓縮後進入到目錄，接著執行<code>gdrive account add</code>，輸入上面取得的用戶端編號與用戶端密碼後，會得到一個連結，複製貼到瀏覽器進行認證</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczO5PxeKR3gqSzNs3AE2Brh3hL53ijfdb45o3HzeLEx8PH9G_mBCfwrwnqrMsBpt7NEpsLKxK_qXku-8BIVoTQr4bvZuYzobDlxd9JvgUohAmSY0tEHX4UvwaN93KaZKsU50HxHIVY07Ot1BS8wSXWN2=w981-h456-rw" alt="gdrive3 : Google Drive CLI Client - 驗證、匯出" title="gdrive3 : Google Drive CLI Client"></figure></div>


<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gdrive account add
# Client ID (輸入用戶端編號)
# Client secrent (輸入用戶端密碼)
# 取得驗證連結 (貼到瀏覽器進行認證)
# 驗證成功顯示 Logged in as xxxxx@gmail.com</pre>



<p>輸入剛剛上面 Add user 中輸入的 gmail 帳號</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNQ0tlovd_Lx_offLztnGAzhPwueEn1Q-c63Shi0G3L3fkB8ZJbC-htu_blKIKlpDj4klyD6NlVH1AfOYl2LHIza66OqPIokwVWVVIXor86179TL7x5MDSrLCeOgXIaZmm2FZAPJzv8SE2ZjCRNxdqb=w1051-h441-rw" alt="gdrive3 : Google Drive CLI Client - 驗證 Google Drive API 1" title="gdrive3 : Google Drive CLI Client"></figure>



<p>遇到下面這個畫面沒關係，點擊顯示進階設定，點擊下方前往「GDrive3」(不安全)</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMwiuWQZKGEtOsgTev8dVkSkUM5e_ZHYmuJKBjywOSiiBTlijIjuQnYSVROat5ihi4SEYA5iVm-br-g5jWkE6zD72cgcYlKbARXXM9IIzk_uH8DoaHx4G-u_0T83uJHTlyfibTB92ItCB2v7LBAR26W=w644-h448-rw" alt="gdrive3 : Google Drive CLI Client - 驗證 Google Drive API 2" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>兩個權限都勾選後點擊繼續</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczMvkcr94IMCBGcZ3_1EFP3rMH7HCFyLyJ4J7Efk6KSZ_MIullJCWw6rBVctY1p3jf9TqOOYQozKCgdNKQGYoQVA6H0keU4ACWRVZmL_h26WryCg9puHYiJNJ5uzUXz5d5BNe2B-4Theg7fO0S7CvZM1=w1044-h739-rw" alt="gdrive3 : Google Drive CLI Client - 驗證 Google Drive API 3" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>驗證成功</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczM1j3v0kab7tsCubxZzph7ttvJarHfEaazkYUQal5E_mUIq7-4Bur73y5FO7Q4bCqmKJDQbpwmQmyRYBAwnQThxk38pskwge36Vvq49EuP-66KkjPV2Mb-gwxdqGCPdZ57ICr9oHaejs0axh09-e8sF=w336-h97-rw" alt="gdrive3 : Google Drive CLI Client - 驗證 Google Drive API 4" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>接著將驗證成功的檔案匯出，輸入<code>gdrive export</code>剛驗證成功的 gmail 帳號</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczNcbmyAoI7ERJDNqlDpUDuTnVVF5OetKG31Y0ryxTsnbxiaaoyFiueUIoOK7Kd7ZV8ej9RNfxGxfywrdavxJxXTwGjA-VlDj8eflJhPPZdSI4jz9EFQKmHxLDzeOujy2HOwzJn981lWXeU0opNjKhRz=w706-h130-rw" alt="gdrive3 : Google Drive CLI Client - 匯出 gdrive 驗證檔" title="gdrive3 : Google Drive CLI Client"></figure></div>


<p>把上面產生的檔案上傳到 VPS 主機上，使用<code>gdrive account import</code>匯入就成功囉~</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczOLk8tqKSEU0-NcgWgSeb1KOYulLXzphCPJcM8foQXR-P1IMat7l2X0e0pssW7JbBhq5MyqOzzX8dXn4v7F82qlw1LiO-a1KHOJ-B-Ggig7Ua3LizCqr8lJh9YS0VOaN8tOnTmH9l8xfL-kYnOcjNSX=w1141-h109-rw" alt="gdrive3 : Google Drive CLI Client - 匯入 gdrive 驗證檔" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h2 class="wp-block-heading para">gdrive3 基本使用</h2>



<p>只要輸入<code>gdrive</code>就可以看到使用說明</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># gdrive
Usage: gdrive &lt;COMMAND>

Commands:
  about        Print information about gdrive
  account      Commands for managing accounts
  drives       Commands for managing drives
  files        Commands for managing files
  permissions  Commands for managing file permissions
  version      Print version information
  help         Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help information</pre>



<p>輸入<code>gdrive files mkdir 資料夾名稱</code>可建立資料夾，小蛙要用來放備份的，因此輸入<code>gdrive files mkdir backup</code>，建立一個名稱為 backup 的資料夾，接著會回傳一個 directory id，之後存取這個資料夾都是認這個 directory id 而不是資料夾名稱喔。</p>



<h3 class="wp-block-heading para">建立資料夾</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># gdrive files mkdir backup
Created directory 'backup' with id: 1MuLg1nlmZwudTdW4MJqhNO1z88i9Vur2</pre>



<p>到 Google 雲端硬碟可以看到成功建立了 backup 資料夾</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AP1GczPALj9qNEhjP_nUQVGBjfl_sjS8N2DwI9xt6jWgF-QRgqnC4jPavznsOC4GuwV-Woydo5Wt7zFfeBAh1cZfd85FFKRGYqrfNbHFraatBoct7yE4m3raEPpgND72DAcR1g_HVmjV11NXNHvnStyn_-61=w505-h252-rw" alt="gdrive3 : Google Drive CLI Client - 我的雲端硬碟" title="gdrive3 : Google Drive CLI Client"></figure></div>


<h3 class="wp-block-heading para">上傳檔案</h3>



<p>這一版不支援前一版可以<code>gdrive sync upload 本機資料夾 雲端資料夾id</code>直接同步整個本機資料夾內的檔案，只能透過以下指另一個一個上傳</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gdrive files upload --parent 1MuLg1nlmZwudTdW4MJqhNO1z88i9Vur2 1.txt
gdrive files upload --parent 1MuLg1nlmZwudTdW4MJqhNO1z88i9Vur2 2.txt
...</pre>



<p>或者是批量把資料夾下的資料都上傳可透過以下指令，不過這樣會在原本要上傳的 backup 資料夾下又在建立一個 backup 資料夾 &#8230; </p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">~/backup# gdrive files upload --parent 1MuLg1nlmZwudTdW4MJqhNO1z88i9Vur2 --recursive ./
Found 2 files in 1 directories with a total size of 70 B
Creating directory 'backup' with id: 1elbAeqJGIA_h8VeKSGveWWuyVL_vZevp
Uploading file 'backup/1.txt' with id: 1HuMgkjhnLwWnCkub3hwfU2WVXvC-o3IQ
Uploading file 'backup/2.txt' with id: 1S76vQWzWtR1AzR-IzxDMPBh2RBzNAvOB
Uploaded 2 files in 1 directories with a total size of 70 B</pre>



<p>大概 gdrive 的教學就到這邊，如果遇到參數不知道怎麼下的時候，只要在最後面加上<code>-h</code>就可以看到指令教學。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/12951/gdrive3-google-drive-cli-client/" data-wpel-link="internal">gdrive3 : Google Drive CLI Client</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/12951/gdrive3-google-drive-cli-client/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PHP Client 操作 Google APIs (1) 開啟與測試 API</title>
		<link>https://noter.tw/8940/google-apis-1-api-explorer/</link>
					<comments>https://noter.tw/8940/google-apis-1-api-explorer/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 16 Jul 2021 06:07:47 +0000</pubDate>
				<category><![CDATA[其他]]></category>
		<category><![CDATA[技巧分享]]></category>
		<category><![CDATA[技術相關]]></category>
		<category><![CDATA[程式開發]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[記下來]]></category>
		<category><![CDATA[Google APIs]]></category>
		<category><![CDATA[Google 服務]]></category>
		<category><![CDATA[API Console]]></category>
		<category><![CDATA[Google Search Console API]]></category>
		<category><![CDATA[Try this API]]></category>
		<category><![CDATA[教學]]></category>
		<category><![CDATA[Google Cloud Platform]]></category>
		<category><![CDATA[Enable Google API]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=8940</guid>

					<description><![CDATA[<p>應該很多人不知不覺中身邊就充滿了 Google 服務吧！舉凡是 Gmail、Google Maps、Google 雲端硬碟、Google 表單、Google 試算表、Google 文件 &#8230;&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/8940/google-apis-1-api-explorer/" data-wpel-link="internal">PHP Client 操作 Google APIs (1) 開啟與測試 API</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>應該很多人不知不覺中身邊就充滿了 <a href="https://www.google.com.tw" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Google<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 服務吧！舉凡是 Gmail、Google Maps、Google 雲端硬碟、Google 表單、Google 試算表、Google 文件 &#8230; 等，這些服務除了透過對應的軟體或網頁使用外，Google 其實也提供了很多 API 服務，通稱 Google APIs ，讓使用者可以透過這些 API 來打造自己的 Google 服務。</p>



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



<p>可能有很多人不懂 Google 提供的 APIs 能做什麼，以及有哪些 Google APIs，只要到  <a href="https://console.cloud.google.com/apis/library" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Google Cloud Platform<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 就可以看到 Google 提供的所有 API，所有你想得到的 Google 服務，幾乎都有對應開放的 API，差別在於每個 API 使用的次數跟頻率有所限制，還有另一個是 Google 開放的 API 裡面「並不會」接露所有功能。</p>



<p>舉個 Google Maps 的例子，使用 Google Maps 時除了地圖、店家資訊及使用者評論等等，中間還有一個熱門時段，讓使用者可以清楚知道哪個時段會比較多人，就可以避開熱門時段，挑個比較少人的時間去，好友當時就是因為 Google Maps API 沒有提供這個功能，因此小蛙才幫忙用爬蟲的方式解決這個問題。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWL_oDuen_qBzMNbYdZK5dhO7gPNmPDQkcPM0YOc_46CTNvh5cV6oVjYGXRHD7ekPEe1Lw5OmF94ZQQqDYMvSJxaujLwDnv92xvapzUX-BPmA4-8Louw_SVq-JArilQ06Rd6kKTpTX_xAFOxr4WdrajSQ=w407-h208-no?authuser=3" alt="Google Maps 熱門時段" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>連上 Google Cloud Platform 可以看到很多各式各樣你想得到或想不到的服務</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXUsdR4ePOskw_zEHJYvimSQypoWYO6SsQTD6GCfBn6TOnBp50Mu9kpk1sQsZjWsoek5gK97lV6STAFv6rbfXUxj0MX5odaaPe7FbgmLnK2DwaRwRa_FtH9SCpU4vzF0ngk26UUXoUV6b_iO_-QKmSmlA=w1236-h850-no?authuser=3" alt="Google Cloud Platform APIs" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<h2 class="para wp-block-heading">開啟 Google APIs</h2>



<p>小蛙這系列都會用 Google Search Console 來當作範例，其他 API 原理基本上都差不多，只是呼叫的方式跟屬性設定有所不同，開始吧！</p>



<p>首先連到 <a href="https://console.cloud.google.com/apis/library" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Google Cloud Platform<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 從上方(1)選取一個要使用 API 的專案(2)，如果沒有專案的話可以建一個新的(3)</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWFT6CzR0i2Y5RvptdJooiHeuWYJLa7EbiOyChF7LY63w0QzMae8BYIKyPwP5Tcxn1ILM4PUPjALTw0CZuZaQnTGKF8jxIdyKugcy5svmcP6WmWXXyBjBGgOaBqAgPysbu_djST_i4EzwLzx6wdwsbdDg=w762-h377-no?authuser=3" alt="Google Cloud Platform Select a project" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>搜尋要開啟的 API (1)，點進去 (2)</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLW4Vne9XTUwgclQcPfh-XHpx00_pbkYywARPO_gNv-EVd2KrabcLVd0RdBz7rJjHp3oCkqgdNWZFvs352bKRPaiP0Oy4flXRGspXFdyalenpxAUT5VfDVvkAiXvtZ7a8PxYwwKL4FBkFhg_kb1TDqh3Hg=w919-h278-no?authuser=3" alt="Google Cloud Platform Keyword Search" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>點上面的 Enable 就可以開啟該 API 了，下面有一些 API 說明可以看看</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWi6McQq0WSsUZC7MEdkczS6MDRqTsVFeOBaGMVp-5VmydFdyy5-gQ_0KE5xp8LhKKVRuojmN1nL2OrbVIcPdKOagGyeiTqhTc4wkFlVE512UfAvFPrbTLYFGXu8P0r9Zy11TNJ8CvTyqNw9X4Q56Y_qg=w623-h327-no?authuser=3" alt="Google Cloud Platform Enable Google Search Console API" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>API 成功開啟後，左邊的 Credentials 可以設定 API 認證的部份，不過這裡小蛙到第三篇文章的時候才會提到</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXOt8yYkjQHUScF-vTgRlnDwHy29kzvsUPc67IWmku0F-PJw8x6DenuKslF_-aXSdWuyyIMA7hRdHMby60lryZki-FUsn8weuVBjpE4cfOfPFjOuVL2rCIU7bFpVcAD18TLZQxjZOKeWx_wVr6ls4OYMg=w261-h272-no?authuser=3" alt="Google Cloud Platform Side Menu" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<h2 class="para wp-block-heading">測試 API 說明</h2>



<p>回到剛剛啟動 Google Search Console API 的頁面，這次點選右邊 TRY THIS API</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXx468noxoeQwCFdKEpcfnNexiK7agGdBvKk5AcjoYvG3ZBvCBAriIh_E2yLQ3VwFrjfXEX7Zct9erixYXxQaFRUk0C9JQvy1uRNIAlsexI8SuNvrVBkfOk1OxuYcPcmP7kEJhX-NZwzqR0d2bMLNgZXQ=w627-h314-no?authuser=3" alt="Google Cloud Platform TRY THIS API" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>開出來的頁面是 Search Console URL Testing Tools API，不過小蛙這邊要用的不是這個 API，而是能取得 Google Search Console 裡面資料的 API，因此點選左上角 (1)</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXV055sMST_O7FgfVpcCjl9ww6oiyueSOOn2mHoM0f9-hN6JHFnaEmpEaBvzWHJYG5oKIp2BnhCmtHUB7MCat4URiREEfSY563bVnknM-A6KtBl_Iox4O4yVVhq6wQ5W9-_hTs-ahuujZTCNnfuDHauCA=w958-h468-no?authuser=3" alt="Google Search Console APIs &gt; URL Testing Tools API (Beta)" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>回到 Google Search Console APIs 首頁後進入 Search Console API</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXlQmNV8QP7dfkg7b7EaLqAbcQCEb_V_svlc2FIWesq5oQ5tPrQ-qT57-BJgddhP59FtcFshozITznDW5GnJc4iHE3KIG7NgUkaVvN1HmqFwhBeoVDm01PBNcgiZ1s6MvciXfjjUDME7t704kMSWT7OkA=w931-h573-no?authuser=3" alt="Google Search Console APIs" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>找到下面的 Try it in your browser</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLVMbYziFhx3dxR9F28UWx3wkZcDtQVnU14rkAAvySVGeMi2SYWSORxoKQMnfn3Tk1FTBeikKbnx3EptXdL3aV0O63oUIicb5md0O0_yST37E2gSzS99p_RchRGxak1URCTXXwv6LJCwx7UfYqIvkHN97A=w622-h449-no?authuser=3" alt="Try out the Google Search Console API" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>接著隨便點一個 api 功能</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXDc68UJJAMl16ASnRzF8bAdvriWeX0bDNvdn08Ix_acpps0V_WZqNOWLuELUoSTT142lzEx4xMyRsOzfcFWvJb3mcLFJ3s-CwPcusGSI_L_-1HsfosX2Fuc8HUJmKEcG_S3kzHaGxsdc3pXniJ4YhDdg=w942-h602-no?authuser=3" alt="Google Search Console APIs &gt; query" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>右邊會開啟一個側欄，這邊就是 Google API 的測試工具了，點選右上角的方框 (1) 可將螢幕放大顯示更多資訊</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXUAKERyhTBWcoSSDmfbzvN4NI5IyDm8Jmr4k9d7Xt6UKiNxcpH8DIHCLa2GTvUrI7ysY7btQVxiMNryzY9r0hQY3vgRCMn9AA1gzB484MlYDFPwIbo0LEbtSjLoM7a_L6U4b7G4eMaYcXtN0375WA27g=w399-h811-no?authuser=3" alt="Google Search Console API &gt; Try this API 1" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>Google Search Console 原本就是以「網站」為目標，因此必填欄位是在 Search Console 裡面的網址 (1)，Request body 的部份填入查詢的參數 (2)，輸入完成後點選 EXECUTE 執行 (3)，下圖 (4) 的地方是真正發送出的 request</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXfwzWrEja8fKmnA0PPyyLqnv0hqZIswmWbV97eqVRpX7fAk4vHt1JQBIu_i_3jIown7IT0Jr7P56sYOVnAk4yY7oEbq8OA1nFGdSc419FBdiu8gXA8DwggmMlcMlFS9nMJ28SOj5zH_OPzAUp-FllncQ=w1150-h697-no?authuser=3" alt="Google Search Console API &gt; Try this API 2" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<h2 class="para wp-block-heading">使用測試 API</h2>



<p>小蛙用記下來 https://noter.tw/ 測試一下 (1)，填入一些必要的參數 (2) 取得 2021-05-01 ~ 2021-07-01 區間的資料，只要回傳前 10 筆就好，點選 (3) 的驚嘆號會顯示有哪些屬性可以設定，確定沒問題後 EXECUTE 送出吧！注意：這邊的 siteUrl 一定要是自己的 Search Console 原本就有的資源才可以，也就是說不能去查別人的，不然就太恐怖了！</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXxhOOd5fA43lv7nABBi3L9YJ0TMd1_RH-6LG6nHEuiVKZvXEIYlEAro-ZsxEmcdprhPEv1131GnKUla5crI-SUTM1bZhSiEvoCdKkZODHyzCo6QI9CkQmxU_jrnVQOP82lhdS9e4XUDIltV50aDK4sNQ=w456-h734-no?authuser=3" alt="Google Search Console API &gt; Try this API 3" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>點了 EXECUTE 後瀏覽器跳出登入畫面，有些可以透過 API Key 來使用，有些則是必須透過 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="SSO Login" width="451" height="495" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>執行成功後，右上角會產生實際送出的 API</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWo34bRGyi15XFeIn6p1_egFpEDrUG3ikfHlhF965Ueu3yLUlrIWZ9b-wIeHxmnBBs8D_BAM0csiOvvRG7SNF_3h5bUP7ASDDHrayL9UipS_4SBTUCTqxLyOg9gVWWrxdSTnlZeLmaZQ9vv7OZBoQvhHg=w669-h144-no?authuser=3" alt="Google Search Console API &gt; Try this API curl" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>右下角則是顯示回傳結果，可以看見在這區間被點擊的次數為 46,812 次，搜尋曝光有 838,324 次 &#8230; 等</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWxy3xjsu-hb7cDZQIT8Rl9UDH1sK4KH2pHha0SQZJ2j-Gx0hoH17yjA9IcrgZ781Ni2TmIRYxVhQB6vCXA1o_hTPLtbz0NuoygsNvgDDE9UMYdddV9inyb_23hknSkRHRdPyjGaajrWZwL0Xi6lsXd-A=w305-h288-no?authuser=3" alt="Google Search Console API &gt; Try this API results 1" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p class="withcode">這看起來好像只能取到很基本的資料？不～來把參數做個調整，加上 <code>aggregationType</code> 及 <code>dimensions</code> 的設定回傳各個頁面的資訊～</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLXhpOjk2WH7VGQn7KoPm1_AHInljAqKgu7x02VM2i2Ub_LHWQI_IP_LKNDX7kaq5xR-txJd7KZCqXLkWgR-fCfdwbdgmI_m1A4qbNn5Ib3YaglDKf9ebSdK0kHabszrHEXwQUtwp3UEf0DE2fEqbJr1CQ=w425-h332-no?authuser=3" alt="Google Search Console API &gt; Request body" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>查詢結果會根據區間內的點擊數排列，看看剛剛我們加的 dimensions 都在 keys 陣列裡面，包含搜尋字串、頁面、來源國家及日期</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AM-JKLWDbjBcT2NFEMd4IepyzdVoo5dVJG04OrpMRY4NLTX9sAsLa6Gb1P4jEuTDIaN_F-7oUr0e08VRkmnCgbazYvQIOKJwnu3vfhJHV0TxZR72RbFvDXm54KEJVP0ZDCZKCzhDL324dX-m4w7sf23b5dtDaw=w437-h322-no?authuser=3" alt="Google Search Console API &gt; Try this API results 2" title="PHP Client 操作 Google APIs (1) 開啟與測試 API"></figure></div>



<p>Google Search Console API 啟用跟測試就到這邊，下一篇將繼續介紹環境設定部份。</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/8940/google-apis-1-api-explorer/" data-wpel-link="internal">PHP Client 操作 Google APIs (1) 開啟與測試 API</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/8940/google-apis-1-api-explorer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
