10

GMail には便利なウィンドウがあり、すべての連絡先を CSV ファイルとしてエクスポートできます。これを行ってブラウザの履歴を見ると、ダウンロードの開始に使用された URL が次のようになっていることがわかります。

https://mail.google.com/mail/c/data/export?exportType=GROUP&groupToExport=%5EMine&out=GMAIL_CSV&tok=rQt5BTUBABA.N0gr2-zKkG9868fM7tF_FQ.fOgeVayblkGavK2AuFjZ2t

この CSV ファイルを毎晩サーバーに自動的にダウンロードするバッチ スクリプトを Python で作成したいと考えていますが、「tok」を取得する方法がわかりません。私は Google の OAuth を調べましたが、人間と対話するプロセスのようですが、利用可能なすべての人間が眠っている午前 3 時にこれを行う必要があります。

これを行うことはできますか、それとも Google が私の電子メール アカウントを非常に "安全" にしているので、無人スクリプトを介してアクセスすることはできませんか?

ありがとうございました!ブライオン・M・エリオット

4

4 に答える 4

5

最初にアカウントとパスワードで認証します ( http://developers.google.com/accounts/docs/AuthForInstalledAppsを参照)

auth=`curl --silent -d Email=whatever@gmail.com -d Passwd=yourpwd -d service=contacts https://www.google.com/accounts/ClientLogin|grep ^Auth=|cut -d= -f2`

謎の「tok」変数を入手。JSONリクエストの一部であることがわかりました:

tok=`curl --silent --header "Authorization: GoogleLogin auth=$auth" "https://www.google.com/s2/gastatus?out=js&rc=0" |sed 's/,/\n/g' |grep AuthToken |cut -d'"' -f6`

CSV をダウンロードします (Google 形式)。これは手動で行う方法とまったく同じです: support.google.com/mail/answer/24911?hl=en

curl -s --stderr - -L -o contacts-google-whatever\@gmail.com-$(date +%Y-%m-%d-%H.%M.%S).csv -H "Authorization:GoogleLogin auth=$auth" --insecure "https://www.google.com/s2/data/exportquery?ac=false&cr=true&ct=true&df=true&ev=true&f=g2&gids=6&gp=true&hl=en-US&id=personal&max=-1&nge=true&out=google_csv&sf=display&sgids=6%2Cd%2Ce%2Cf%2C17&st=0&tok=$tok&type=4"

変数「out」は、google_csv、outlook_csv、vcard のいずれかです。私のコードは bash です。curl コマンドを Python の同等のものに変更することをお勧めします。重要な情報は、変数と URL です。

于 2014-08-11T03:24:20.363 に答える
2

私はいくつかの同様の解決策を探していましたが、自分で行った準備ができている解決策を見つけることができなかった原因です:(怠惰なスクリプトについてはご容赦ください。動作させたかっただけです:D)

#!/bin/sh 
# google api requirements:
# https://developers.google.com/gdata/articles/using_cURL
# https://developers.google.com/gdata/faq#clientlogin
# https://developers.google.com/google-apps/contacts/v3/
# https://developers.google.com/google-apps/contacts/v3/reference
# json parser:
# https://github.com/dominictarr/JSON.sh#jsonsh
# recommendation(optional):
# https://developers.google.com/accounts/docs/OAuth2UserAgent

# echo "logging in to google and saving contact with given caller-number."
Auth=$(curl --silent https://www.google.com/accounts/ClientLogin --data-urlencode Email=${Email} --data-urlencode Passwd=${Passwd} -d accountType=GOOGLE -d source=Google cURL-Example -d service=cp | grep Auth | cut -d= -f2)
curl -o ${dir}/${tmpfile} --silent --header "Authorization: GoogleLogin auth=$Auth" "https://www.google.com/m8/feeds/contacts/$Email/full?v=3.0&q=$2&alt=$Format"

解決策にたどり着くのに役立つかもしれません;)

于 2012-11-07T19:30:46.443 に答える
0

gmail apiを見てみてください:http ://code.google.com/apis/gmail/oauth/code.html

于 2012-01-19T16:51:29.073 に答える
0

何も見つからなかったので、これを行う小さなツールを作成しました。ここで見つけることができますhttps://github.com/gedl/gc-csv

Google の連絡先をカンマ区切りのファイルにエクスポートしたり、コンソールにエクスポートしたり、VOIP 電話 (Incom ICW1000G) にアップロードしたりできます。

お役に立てば幸いです。

于 2016-05-21T00:02:14.930 に答える