Bry*_*yon 10 python gmail export contacts google-contacts-api
GMail有一个方便的窗口,可以将所有联系人导出为CSV文件.如果您执行此操作然后查看浏览器的历史记录,您会看到用于启动下载的URL类似于:
我想在Python中编写一个批处理脚本,它会每晚自动将这个CSV文件下载到我的服务器,但我无法弄清楚如何获得"tok".我已经研究过Google的OAuth,但它似乎是一个人机交互过程,而我需要在凌晨3点发生这种情况,因为所有可用的人都会睡着.
可以这样做,还是Google让我的电子邮件帐户"安全",以至于我无法通过无人参与的脚本访问它?
谢谢!Bryon M. Elliott
首先使用您的帐户和密码进行身份验证(请参阅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`
Run Code Online (Sandbox Code Playgroud)
获取神秘的“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`
Run Code Online (Sandbox Code Playgroud)
下载 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"
Run Code Online (Sandbox Code Playgroud)
变量“out”可以是 google_csv、outlook_csv、vcard 之一。我的代码是 bash,您可能需要将curl 命令更改为Python 等效命令。重要的信息是变量和 URL。
| 归档时间: |
|
| 查看次数: |
3716 次 |
| 最近记录: |