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.

Attaching URLs to activities

The Google+ Domains API allows you to attach a URL when you create a post, such as an article that is related to the post.

Creating a new post with a URL attachment

The following example demonstrates how to create a post with a URL attachment that is viewable by all users 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 msg = "Solitaire.... #mondays #workinghard";

// Create the activity and populate the contents
activity = new Activity();
activity.setObject(new Activity.PlusDomainsObject());
activity.getObject().setContent(msg);

// Attach the link
Activity.PlusDomainsObject.Attachments attachment = new Activity.PlusDomainsObject.Attachments();
attachment.setObjectType("article");
attachment.setUrl("http://en.wikipedia.org/wiki/Solitaire");
List<Activity.PlusDomainsObject.Attachments> attachments = new ArrayList();
attachments.add(attachment);    // You can also add multiple attachments to the post
activity.getObject().setAttachments(attachments);

// 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'
message = 'Solitaire.... #mondays #workinghard'
url = 'http://en.wikipedia.org/wiki/Solitaire'

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

Protocol

Request

Write an activity by sending an HTTP POST request to the Activities.insert method.

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

To attach a URL include the object.attachments property, for example:

{
  "object": {
    "attachments": [{
        "url": "http://goo.gl/f08WO",
        "objectType": "article"
    }],
    "originalContent": "Ink42 should try that too!",
  },
  "access": {
    "items": [{
        "type": "domain"
    }],
    "domainRestricted": true
  }
}

The result of the HTTP POST request with the activity object above creates the following post with a thumbnail image: Shows an example post that uses the URL from above to retrieve a
  preview thumbnail and title from the target page.

See the Activities.insert REST API method.

Attaching URLs with an embedded video

If you attach a URL to an article, which embeds a video, Google+ displays a full-size preview image of the video if the page contains appropriate video markup information with the embedded video play link. When the video preview in the stream is clicked, the video plays within the stream as an embedded video.

For example, you can post a YouTube video page and Google+ displays the embedded video in the stream.

Example post in the stream that displays an embedded YoutTube video

When posting articles that contain videos but the pages does not have supported markup information, the post instead displays a small thumbnail. In the example stream post below, a Lifehacker video page is linked and displays the preview thumbnail:

Example post with video thumbnail instead of an embedded video

In addition to linking to articles that contain videos, you can also upload videos and attach them to your posts. See Attaching media to posts.