命令行中的google api
shoogle的Python项目详细描述
幕布
使用shell中的google api。例如,使用 urlshortener服务:
$ echo '{"shortUrl": "http://goo.gl/Du5PSN"}' | shoogle execute urlshortener:v1.url.get - { "status": "OK", "id": "http://goo.gl/Du5PSN", "longUrl": "http://1.bp.blogspot.com/-R0HSXDqlJI8/Tr67i-kr7hI/AAAAAAABMko/gaId6iYuhjA/s1600/12_%252520Cross%252520that%252520bridge%252520when%252520we%252520come%252520to%252520it.jpg", "kind": "urlshortener#url" }
安装
依赖关系
- Python>;=3.0
来自PYPI
$ sudo pip install shoogle
来源
$ wget https://github.com/tokland/shoogle/archive/master.zip $ unzip master.zip $ cd shoogle-master $ sudo pip install pypandoc $ sudo python setup.py install
功能
- 不可知地公开api中的所有服务。
- 提供OAuth2身份验证的基础结构(控制台或 Qt/GTK浏览器)。
- 显示来自google discovery api的信息,以帮助构建 json请求。
- 保存每组作用域的凭据。
设置:配置api和密钥
- 必须启用要使用的服务并创建所需的 API Manager中的密钥或机密文件。每次服务 有自己的策略,请查看google文档了解更多 细节。
命令
显示
以增量方式显示服务/资源/方法的详细信息:
$ shoogle show adexchangebuyer2:v2beta1 - Ad Exchange Buyer API II adexchangebuyer:v1.2 - Ad Exchange Buyer API ... youtubeAnalytics:v1beta1 - YouTube Analytics API youtubereporting:v1 - YouTube Reporting API
$ shoogle show short urlshortener:v1 - URL Shortener API
$ shoogle show urlshortener:v1 urlshortener:v1.url
$ shoogle show urlshortener:v1.url urlshortener:v1.url.get - Expands a short URL or gets creation time and analytics. urlshortener:v1.url.insert - Creates a new short URL. urlshortener:v1.url.list - Retrieves a list of URLs shortened by a user.
$ shoogle show urlshortener:v1.url.get [INFO] Response (level=0, --debug-response-level=N to change): { "$ref": "Url" } [INFO] Request (level=1, --debug-request-level=N to change): { "shortUrl": "(string) The short URL, including the protocol - required" }
执行
- 展开一个简短的url:
$ cat get-longurl.json { "key": "YOUR_SECRET_KEY", // You can use JS comments! "shortUrl": "http://goo.gl/Du5PSN" } $ shoogle execute urlshortener:v1.url.get get-longurl.json { "status": "OK", "id": "http://goo.gl/Du5PSN", "longUrl": "http://1.bp.blogspot.com/-R0HSXDqlJI8/Tr67i-kr7hI/AAAAAAABMko/gaId6iYuhjA/s1600/12_%252520Cross%252520that%252520bridge%252520when%252520we%252520come%252520to%252520it.jpg", "kind": "urlshortener#url" }
- jq是命令行json 生成器/分析器。这个例子展示了如何从json上传视频 模板并从响应中提取id:
$ cat upload-video.template.json { "part": "snippet", "body": { "snippet": { "title": $title, "description": $description } } }
$ jq -n -f upload-video.template.json --arg title "Chess" --arg description "Norway Chess" | shoogle execute -c your_client_id.json youtube:v3.videos.insert - -f chess.mp4 | jq -r '.id' wUArz2nPGqA
更多
- 许可证:GNU/GPLv3。
反馈
- 问题:请仅在报告包的错误时打开问题。如果你 在如何使用api本身(auth是什么)方面有问题 必需,如何创建这些身份验证文件,如何生成请求 参数、配额管理等),使用Google Forums或 StackOverflow。
- Want to donate?
更改日志
[0.1.0]
- 为OAuth2身份验证(控制台和 浏览器)。
- 公开python gooogle api支持的所有服务。