mkoistinen
mkoistinen

Reputation: 7773

Simple Python code for posting to Google+

I'd like to post to G+ from my application much like I already do in a few lines of code to Twitter. I've been looking at the sample code at code.google.com, and, while the API looks very powerful, the documentation makes this simple task seem immensely complicated. Can someone provide a pointer to a simple snippet of code that simply posts some text to my own G+ account?

Upvotes: 2

Views: 3271

Answers (2)

Joanna
Joanna

Reputation: 2176

The best way to do this is to use an Interactive Post. There is no way to programmatically write a post on behalf of a user, but you can create a Share option for the user with prefilled text and recipients. It renders as a button. There's an example below.

Learn more at: https://developers.google.com/+/web/share/interactive

Also, the code.google.com resource is out of date. All updated samples are at https://github.com/googleplus/. Specifically, you are probably interested in the PhotoHunt Server in Python to see all of the features that the Google+ API offers (https://github.com/googleplus/gplus-photohunt-server-python).

For an example of an Interactive Post in the PhotoHunt, check https://github.com/googleplus/gplus-photohunt-server-python/blob/master/static/js/controllers.js#L253.

Upvotes: 5

julienfr112
julienfr112

Reputation: 2137

http://code.google.com/p/google-api-python-client/ should fit your needs.

There is an example ( http://code.google.com/p/google-api-python-client/source/browse/samples/plus/plus.py ) with some google+ actions:

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

Upvotes: -1

Related Questions