<?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>composer &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/composer/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Fri, 06 Aug 2021 13:22:08 +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>composer &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>PHP Client 操作 Google APIs (2) 安裝 Google API Client for PHP</title>
		<link>https://noter.tw/8944/google-apis-2-google-api-client-for-php/</link>
					<comments>https://noter.tw/8944/google-apis-2-google-api-client-for-php/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 07:40:57 +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 Search Console API]]></category>
		<category><![CDATA[Google Cloud Platform]]></category>
		<category><![CDATA[Google Client]]></category>
		<category><![CDATA[教學]]></category>
		<category><![CDATA[Google APIs Client Library for PHP]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[安裝]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=8944</guid>

					<description><![CDATA[<p>Google APIs 開啟的方法可參考上一篇文章：PHP Client 操作 Google APIs (1) 開啟與測試 API，這篇文章繼續記錄使用 Google API Client 來操作 G&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" 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> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>Google APIs 開啟的方法可參考上一篇文章：<a href="https://noter.tw/8940/google-apis-1/" data-wpel-link="internal">PHP Client 操作 Google APIs (1) 開啟與測試 API</a>，這篇文章繼續記錄使用 Google API Client 來操作 Google Search Console APIs。</p>



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



<p>上一篇文章我們示範了怎麼使用 Google 提供的 API 測試工具，透過這些工具產生相關 REST 指令，同時 Google 也提供 Java 及 Python 版本的使用範例，只要點進 <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Google Search Console APIs<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 就可以看到。</p>



<p>但是小蛙今天要使用的不是 Java 及 Python，而是 PHP 版本的 Client (beta)，只要點進 <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/libraries#php" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Install Client Libraries<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 拉到下面可以看到各種版本的 Client，將頁籤切換到 PHP，或是其它自己擅長的語言～點選 Get the latest&nbsp;<a href="https://github.com/google/google-api-php-client" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">Google Search Console API client library for PHP (beta)<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/AM-JKLX9CBG9wuYorqrlOuCWgAYOQlWD82BHOBZepvZ2VXxMkut7YR6XT8G_1yJcbLGiPo5QQ7pMEOgs2dPkAVgPNkSQ4SBFdWRI6pPB9nJnwH2beMtZGnff-N_Hg24WyUPHNUVk_YaAX0ia77X13Okfa1xW4w=w877-h158-no?authuser=3" alt="Google API Client PHP " title="PHP Client 操作 Google APIs (2) 安裝 Google API Client for PHP"></figure></div>



<p>接著開啟 Github 頁面，PHP 版本需在 5.6.0 以上才可以使用，並且需要透過 composer 安裝，沒有 composer 的話可參考<a href="https://getcomposer.org/doc/00-intro.md" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">這邊<span class="wpel-icon wpel-image wpel-icon-6"></span></a>。安裝好後使用以下指令安裝</p>



<pre class="wp-block-preformatted withcode">composer require google/apiclient:^2.10</pre>



<p>安裝完 PHP Client 後，在要使用 Google APIs 的 PHP 最上面加上</p>



<pre class="wp-block-preformatted withcode">require_once '/path/to/your-project/vendor/autoload.php';</pre>



<p>就可以載入 Google API 的相關工具了，如果沒有或真的不想裝 composer 的話，其實也有提供直接下載的版本，只要到 <a href="https://github.com/googleapis/google-api-php-client/releases" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">這邊<span class="wpel-icon wpel-image wpel-icon-6"></span></a> 去下載適合的版本，解壓縮後同樣在要使用 Google APIs 的 PHP 加入上面 require_once (注意路徑正確性) 就可以使用 Google API 了。</p>



<p>接著建一個 PHP 檔案，新增一個 Google_Client() 物件出來，如果下載或設定正確的話，畫面上應該空白不會噴任何錯誤</p>



<pre class="wp-block-preformatted withcode">&lt;?php
 ini_set('display_errors', '1');
 error_reporting(E_ALL);
 // 換成自己的實際路徑
 require_once '../googleapiclient/vendor/autoload.php';
 $client = new Google_Client();
?&gt;</pre>



<p>如果出現下面這種錯誤，可能是沒安裝正確或是路徑指定錯誤，再檢查看看是哪裡有問題。</p>



<pre class="wp-block-preformatted withcode"><strong>Fatal error</strong>: Uncaught Error: Class 'Google_Client' not found in /var/www/xxx.php:6 Stack trace: #0 {main} thrown in&nbsp;<strong>/var/www/test/xxx.php</strong>&nbsp;on line&nbsp;<strong>6</strong></pre>



<p>這篇文章比較短，只著重在 PHP 版本的安裝，下一篇文章再繼續介紹怎麼使用 OAuth 登入並查詢 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/8944/google-apis-2-google-api-client-for-php/" data-wpel-link="internal">PHP Client 操作 Google APIs (2) 安裝 Google API Client for PHP</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/8944/google-apis-2-google-api-client-for-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
