用于发布到Google+的简单Python代码

时间:2013-08-02 14:21:54

标签: python google-plus

我想从我的应用程序发布到G +,就像我已经在几行代码中发布到Twitter一样。我一直在查看code.google.com上的示例代码,虽然API看起来非常强大,但文档使这个简单的任务看起来非常复杂。有人可以提供指向简单的代码片段的指针,只需将一些文本发布到我自己的G +帐户吗?

2 个答案:

答案 0 :(得分:5)

执行此操作的最佳方法是使用交互式帖子。无法以编程方式代表用户编写帖子,但您可以为具有预填充文本和收件人的用户创建“共享”选项。它呈现为一个按钮。下面有一个例子。

了解详情:https://developers.google.com/+/web/share/interactive

此外,code.google.com资源已过期。所有更新的样本均为https://github.com/googleplus/。具体来说,您可能对Python中的PhotoHunt服务器感兴趣,以查看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

答案 1 :(得分:-1)

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']