Legacy Google+ APIs have been shut down as of March 7, 2019. Changes to the shutdown plan have been made recently which may mitigate its effect on some developers. Learn more.

Google+ integrations for web and mobile apps have also stopped functioning as of March 7, 2019. Learn more.

Resharing posts

You can reshare an existing post with the Activities.insert method by attaching an existing post to your post.

The following example demonstrates how to reshare an existing post and to share that post within your G Suite domain.

Java

// This sample assumes a client object `plusDomains` has been created
// and your app has an access token to use on behalf of the user.
// To learn more about creating a client, see the OAuth 2.0 example:
//  https://developers.google.com/+/domains/authentication/

import com.google.api.services.plusDomains.model.Acl;
import com.google.api.services.plusDomains.model.Activity;
import com.google.api.services.plusDomains.model.PlusDomainsAclentryResource;

String activityId = "z1234z"

String msg = "This was a great post!";

// Create the activity and populate the contents
Activity activity = new Activity();
activity.setObject(new Activity.PlusDomainsObject().setId(activityId));
activity.setAnnotation(msg);

// Set the activity to be visible only to your domain
PlusDomainsAclentryResource acl = new PlusDomainsAclentryResource();
acl.setType("domain");
Acl aclEntries = new Acl();
aclEntries.setItems(new ArrayList());
aclEntries.getItems().add(acl);
aclEntries.setDomainRestricted(true); // Required, this does the domain restriction
activity.setAccess(aclEntries);

// Post the activity
Activity newActivity = plusDomains.activities().insert("me", activity).execute();

Python

# This sample assumes a client object `service` has been created and
# your app has an access token to use on behalf of the user.
# To learn more about creating a client, see the OAuth 2.0 example:
#  https://developers.google.com/+/domains/authentication/

import pprint

# Set the user's ID to 'me': requires the plus.me scope
user_id = 'me'
activity_id = 'z1234z'
message = 'This was a great post!'

# Insert an Activity with a URL attachment
print('Insert activity')
result = service.activities().insert(
    userId = user_id,
    body = {
        'object' : {
            'id' : activity_id,
         },
         'annotation' : message,
         'access' : {
             'items' : [ {
                 'type' : 'domain'
             } ],
             'domainRestricted' : True
         }
     }).execute()
print('result = %s' % pprint.pformat(result))

Protocol

Request

POST https://www.googleapis.com/plusDomains/v1/people/{userId}/activities

The following example is the JSON request body for posting an activity (Activities.insert) with a reshared post attachment:

{
  "annotation": "This was a great post!",
  "object": {
    "id":"z1234z"
  },
  "access": {
    "kind": "plus#acl",
    "items": [{
        "type": "domain"
    }],
    "domainRestricted": true
  }
}

Example

The following command demonstrates a request to the Activities.insert method and assumes that you already have an OAuth token for your user:

curl -v -H "Content-Type: application/json" -H "Authorization: OAuth$ACCESS_TOKEN" -d "{"annotation": "This was a great post!","object":{"id":"z1234z"},"access":{"kind":"plus#acl","items":[{"type":"domain"}],"domainRestricted":true}}" -X POST https://www.googleapis.com/plusDomains/v1/people/{userId}/activities

See the Activities.insert REST API method.

Send feedback about...

Google+ Domains API
Google+ Domains API