<?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>润物无声 &#187; Shell</title>
	<atom:link href="http://blog.zhourunsheng.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zhourunsheng.com</link>
	<description>天空一朵雨做的云</description>
	<lastBuildDate>Sat, 08 May 2021 05:17:21 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>脚本方式获取Google ClientLogin Auth Token</title>
		<link>http://blog.zhourunsheng.com/2011/07/%e8%84%9a%e6%9c%ac%e6%96%b9%e5%bc%8f%e8%8e%b7%e5%8f%96google-clientlogin-auth-token/</link>
		<comments>http://blog.zhourunsheng.com/2011/07/%e8%84%9a%e6%9c%ac%e6%96%b9%e5%bc%8f%e8%8e%b7%e5%8f%96google-clientlogin-auth-token/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 06:06:53 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=190</guid>
		<description><![CDATA[<p>在开发基于Google服务的应用程序中，有很多的情况都需要获取Auth Token。 本文编写了一个简单的sh [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2011/07/%e8%84%9a%e6%9c%ac%e6%96%b9%e5%bc%8f%e8%8e%b7%e5%8f%96google-clientlogin-auth-token/">脚本方式获取Google ClientLogin Auth Token</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>在开发基于Google服务的应用程序中，有很多的情况都需要获取Auth Token。</p>
<p>本文编写了一个简单的shell脚本文件，可方便程序开发人员快速的获取到Auth Token来调试程序。</p>
<p> 本示例程序获取的Googel服务为ah，即Google App Engine，如果需要获取其他服务的token，只要修改脚本中的 service=ah 为自己的服务即可。</p>
<p><strong>Google 常用服务和Service Name 对照表</strong></p>
<table width="400">
<tbody>
<tr>
<th>Google API</th>
<th>Service name</th>
</tr>
<tr>
<td>Google Analytics Data APIs</td>
<td><code>analytics</code></td>
</tr>
<tr>
<td>Google Apps APIs<br />
<em>(Domain Information &amp; Management)</em></td>
<td><code>apps</code></td>
</tr>
<tr>
<td>Google Base Data API</td>
<td><code>gbase</code></td>
</tr>
<tr>
<td>Google Sites Data API</td>
<td><code>jotspot</code></td>
</tr>
<tr>
<td>Blogger Data API</td>
<td><code>blogger</code></td>
</tr>
<tr>
<td>Book Search Data API</td>
<td><code>print</code></td>
</tr>
<tr>
<td>Calendar Data API</td>
<td><code>cl</code></td>
</tr>
<tr>
<td>Google Code Search Data API</td>
<td><code>codesearch</code></td>
</tr>
<tr>
<td>Contacts Data API</td>
<td><code>cp</code></td>
</tr>
<tr>
<td>Documents List Data API</td>
<td><code>writely</code></td>
</tr>
<tr>
<td>Finance Data API</td>
<td><code>finance</code></td>
</tr>
<tr>
<td>Gmail Atom feed</td>
<td><code>mail</code></td>
</tr>
<tr>
<td>Health Data API</td>
<td><code>health</code><br />
<code>weaver</code> (H9 sandbox)</td>
</tr>
<tr>
<td>Maps Data APIs</td>
<td><code>local</code></td>
</tr>
<tr>
<td>Picasa Web Albums Data API</td>
<td><code>lh2</code></td>
</tr>
<tr>
<td>Sidewiki Data API</td>
<td><code>annotateweb</code></td>
</tr>
<tr>
<td>Spreadsheets Data API</td>
<td><code>wise</code></td>
</tr>
<tr>
<td>Webmaster Tools API</td>
<td><code>sitemaps</code></td>
</tr>
<tr>
<td>YouTube Data API</td>
<td><code>youtube</code></td>
</tr>
</tbody>
</table>
<p> Google Service 评测请参照<a href="http://ruscoe.net/google/google-account-service-names/" target="_blank"> Google Account Service Names</a>（Google工程师<strong>Tony Ruscoe</strong>）</p>
<p>脚本代码如下（get_auth_token.sh）：</p>
<pre>#!/bin/sh

# Get user email
read -p "Email: " EMAIL

# Get user password
stty -echo
read -p "Password: " PASSWORD; echo &gt;&amp;2
stty echo

# check and download cacert file
CACERTFILE="/tmp/cacert.pem"
if [ ! -f "$CACERTFILE" ]; then
  wget http://curl.haxx.se/ca/cacert.pem -O $CACERTFILE
else
  echo "cacert exist!!!"
fi

# Get a user auth token
echo Getting token from https://www.google.com/accounts/ClientLogin ... &gt;&amp;2
AUTH=$(CURL_CA_BUNDLE=$CACERTFILE 
	curl -S --location 

https://www.google.com/accounts/ClientLogin

	-d Email=$EMAIL 
	-d Passwd=$PASSWORD 
	-d accountType=HOSTED_OR_GOOGLE 
	-d source=carey 
	-d service=ah 
	--header 'Content-Type:application/x-www-form-urlencoded' 
	2&gt;/dev/null 
	| awk -F= '$1 ~ /Auth/ {print $2}')

if [ -z "${AUTH}" ]; then
  echo "Auth error" &gt;&amp;2
  exit
else
  echo "Auth="$AUTH
fi</pre>
<p> </p>
<p>程序使用如下：</p>
<p>$ ./get_auth_token.sh</p>
<p>Email:            输入自己的Google帐号</p>
<p>Password:    输入自己的Google密码</p>
<p>Auth=DQAAALIAAABNfSYKsytsIx_vzFOG_iHVO4Zv8su6hyn-5cTCtObnLTd1X8K0TDoNC5zdRZTg2NQtn6S47Jw1t3ZfE2J</p>
<p>qDhR_x4KezoWYufUloCVA_pkC3g1vAcy6KIGcqiSH2hecJa5UH9yuURyF7_ODS6ysjYZ0JC9WnuF3vsx_9mO4xFGOGtyw</p>
<p>xMYfGC-j801I1Pna0AJ48T-lCeU1yEiTyUUsLPVszWrvg5ae4BPOtTaZxD_lU4lJhYAXtvLNN1ZGdLJ_huI</p>
<p>最后可以利用获取到的Auth Token来访问google的服务了。</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2011/07/%e8%84%9a%e6%9c%ac%e6%96%b9%e5%bc%8f%e8%8e%b7%e5%8f%96google-clientlogin-auth-token/">脚本方式获取Google ClientLogin Auth Token</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2011/07/%e8%84%9a%e6%9c%ac%e6%96%b9%e5%bc%8f%e8%8e%b7%e5%8f%96google-clientlogin-auth-token/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
