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 photos and videos to activities

You can use the Google+ Domains API to create posts that attach photos or videos and display a full-size preview image when viewed in the stream. For example:

A sample post showing that an uploaded image was attached to the post

If the video that you would like to include in a post is already hosted on YouTube or Vimeo, you can create a post with a link to the video instead of reuploading it.



Your app must include the following scopes:

Grants the app permission to use the special value me to represent the authenticated user. Does not apply to apps that use domain-wide delegation of authority.
Required - Grants permission for the app to upload photos and videos on behalf of the user.
Required - Grants permission for the app to create posts or comments on behalf of a user. The Google+ Domains API only allows creation of restricted posts, and only allows comments to be added to restricted posts.

Supported media sizes

This method supports media upload. Uploaded files must conform to these constraints:

  • Maximum file size: 36MB for a photo, 1GB for a video
  • Accepted Media MIME types: image/* , video/*

Uploads will not count against quota if photos are less than 2048 pixels on their longest side or videos are less than 15 minutes in length.

Creating a new post with a photo or video attachment

To upload a video or image to Google+, you should follow these steps:

  1. Upload the image or video using the Media.insert method. Google+ will return a media ID that identifies the media object.
  2. Post the image or video by using the Activities.insert method and specifying the associated media ID and objectType property as "video" or "photo".

The following example demonstrates how to upload a photo or video using the Media.insert method and then attach the uploaded object to a new activity on behalf of the user.


// 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.PlusDomains.Media.Insert
import com.google.api.services.plusDomains.model.Acl;
import com.google.api.services.plusDomains.model.Activity;
import com.google.api.services.plusDomains.model.Media;
import com.google.api.services.plusDomains.model.PlusDomainsAclentryResource;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

// Upload an image using Media.insert
String userId = "me"  // Requires the plus.me scope
URL fileUrl = ClassLoader.getSystemResource("cat.jpg");
File jpegFile;

try {
  System.out.println("** Url of cat.jpg: " + fileUrl.toURI());
  jpegFile = new File(fileUrl.toURI());
} catch (URISyntaxException e) {
  throw new IOException(e);

Media mediaDescription = new Media();
mediaDescription.setDisplayName("A picture of a cat");
Insert insertRequest = plusDomains.media().insert(userId, "cloud",
    mediaDescription, new FileContent("image/jpeg", jpegFile));
Media result = insertRequest.execute();
String mediaId = result.getId();

// Now create a post using the uploaded image

// Create the activity and populate the contents
Activity activity = new Activity();
activity.setObject(new PlusDomainsObject());
activity.getObject().setContent("Grumpy cat.... #mondays #caturday");

// Attach the photo
PlusDomainsObject.Attachments attachment = new PlusDomainsObject.Attachments();
attachment.setObjectType("photo");    // Or set to "video" for uploaded videos
List<PlusDomainsObject.Attachments> attachments = new ArrayList<PlusDomainsObject.Attachments>();
attachments.add(attachment);    // You can also add multiple attachments to the post

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

// Post the activity
Activity newActivity = plusDomains.activities().insert(userId, activity).execute();
System.out.println("New activity created with ID " + newActivity.getId());
System.out.println("URL: " + newActivity.getUrl());

You can attach a video to a post by specifying the object type as video in the attachment.setObjectType("video") method. You can also attach multiple uploaded media files to a post by passing a list of attachments to the setAttachments method.


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

# Upload a picture
# This example assumes the file is in the same directory as this code
print('Uploading a picture of a cat')
result = service.media().insert(
    media_body = 'cat.jpg',
    body = {'displayName': 'cat.jpg'},
    userId = user_id,
    collection = 'cloud',
print('result = %s' % pprint.pformat(result))

media_id = result.get('id')
print('MediaID of cat.jpg: %s' % media_id)

# Insert an Activity that uses the inserted photo
print('Insert activity')
result = service.activities().insert(
    userId = user_id,
    body = {
        'object' : {
            'content' : 'Grumpy cat.... #mondays #caturday',
            'attachments' : [ {
                'objectType' : 'photo',
                'id' : media_id,
            } ]
        'access' : {
            'items' : [ {
                'type' : 'domain'
            } ],
            'domainRestricted' : True
print('result = %s' % pprint.pformat(result))


You can use the REST APIs directly to upload media and then attach the uploaded media to a new activity.


Make requests to the following endpoints:

POST https://www.googleapis.com/upload/plusDomains/v1/people/{userid}/media/cloud
POST https://www.googleapis.com/plusDomains/v1/people/{userid}/activities
A string specifying the ID of the user to upload the media on behalf of. The alias me can be used to identify the authenticated user if the https://www.googleapis.com/auth/plus.me scope has been granted.


$ curl --header "Authorization: OAuth $ACCESS_TOKEN" --header "Content-Type: image/jpeg" --data-binary "@cat.jpg" -X POST https://www.googleapis.com/upload/plusDomains/v1/people/<user_id>/media/cloud

The above uploads the file cat.jpg to a staging location in Google+ for posting. Upon successful upload, Google+ returns a JSON object that contains the media ID of the uploaded image or video, as well as a media URL that you can use to access the uploaded media. For example:

 "kind": "plus#media",
 "etag": "\"N8Crhx2MRIb1X_HvUcpeIVYmOzs/_9fcjJozO_0SHTeD1DFG9XEd5PM\"",
 "id": "0123456789.9876543210",
 "published": "2013-07-04T21:46:02.000Z",
 "author": {
  "id": "106189723444098348646",
  "displayName": "Larry Page",
  "url": "https://plus.google.com/+LarryPage",
  "image": {
   "url": "https://lh3.googleusercontent.com/-Y86IN-vEObo/AAAAAAAAAAI/AAAAAAACk4w/yvxY4GMx_8k/s120-c/photo.jpg"
 "height": 335,
 "width": 480,
 "mediaUrl": "https://lh3.googleusercontent.com/-DCUbbO6yVO4/UHSbGsuMUCI/AAAAAAAAAA4/w4jnsP82Ukk/s512/365f6009-8673-4683-9b59-1859d15d67fd",
 "sizeBytes": "36051",
 "statusForViewer": {
  "canComment": false,
  "canPlusone": false

Use the returned media id, which would be 0123456789.9876543210 in the example above, to attach the image to a post. The request body to the Activities.insert method would be in the following format:

  "object" : {
    "content" : "Grumpy cat.... #mondays #caturday",
    "attachments" : [ {
       "objectType" : "photo",
       "id" : "0123456789.9876543210",
    } ]
  "access" : {
    "items" : [ {
        "type" : "domain"
    } ],
    "domainRestricted" : true

The JSON object is sent in an HTTP POST to the Activities.insert method.

curl -v -H "Content-Type: application/json" -H "Authorization: OAuth$ACCESS_TOKEN" -d "{"object":{"content":"Grumpy cat.... #mondays #caturday","attachments":[{"objectType" : "photo","id" : "0123456789.9876543210",}]},"access":{"items":[{"type": "domain"}],"domainRestricted":true}}" -X POST https://www.googleapis.com/plusDomains/v1/people/{user_id}/activities

See the Media.insert and Activities.insert REST API methods.

Send feedback about...

Google+ Domains API
Google+ Domains API