【发布时间】:2013-08-02 14:21:53
【问题描述】:
我想从我的应用程序发布到 G+,就像我已经在 Twitter 上写了几行代码一样。我一直在 code.google.com 上查看示例代码,虽然 API 看起来非常强大,但文档让这个简单的任务看起来非常复杂。有人可以提供一个简单的 sn-p 代码指针,它只是将一些文本发布到我自己的 G+ 帐户?
【问题讨论】:
标签: python google-plus
我想从我的应用程序发布到 G+,就像我已经在 Twitter 上写了几行代码一样。我一直在 code.google.com 上查看示例代码,虽然 API 看起来非常强大,但文档让这个简单的任务看起来非常复杂。有人可以提供一个简单的 sn-p 代码指针,它只是将一些文本发布到我自己的 G+ 帐户?
【问题讨论】:
标签: python google-plus
最好的方法是使用交互式帖子。无法以编程方式代表用户撰写帖子,但您可以使用预填充文本和收件人为用户创建共享选项。它呈现为一个按钮。下面有一个例子。
了解更多信息:https://developers.google.com/+/web/share/interactive
此外,code.google.com 资源已过期。所有更新的样本都在https://github.com/googleplus/。具体来说,您可能对 Python 中的 PhotoHunt Server 感兴趣,以了解 Google+ API 提供的所有功能 (https://github.com/googleplus/gplus-photohunt-server-python)。
有关 PhotoHunt 中交互式帖子的示例,请查看 https://github.com/googleplus/gplus-photohunt-server-python/blob/master/static/js/controllers.js#L253。
【讨论】:
http://code.google.com/p/google-api-python-client/ 应该满足您的需求。
有一个示例 (http://code.google.com/p/google-api-python-client/source/browse/samples/plus/plus.py) 包含一些 google+ 操作:
import sys
from oauth2client import client
from apiclient import sample_tools
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'plus', 'v1', __doc__, __file__,
scope='https://www.googleapis.com/auth/plus.me')
try:
person = service.people().get(userId='me').execute()
print 'Got your ID: %s' % person['displayName']
【讨论】: