Configure your App

You must instantiate a client to make requests to the API. All requests to the Groups Settings API require authentication.

The following code demonstrates how to configure your client and authenticate using OAuth 2.0 for native applications.

Java


import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;

import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;

import com.google.api.services.groups-settings.v1.Groupssettings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

...

  public void setUp() throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();

    // The clientId and clientSecret are copied from the API Access tab on
    // the Google APIs Console
    String clientId = "YOUR_CLIENT_ID";
    String clientSecret = "YOUR_CLIENT_SECRET";

    // Or your redirect URL for web based applications.
    String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
    String scope = "https://www.googleapis.com/auth/apps.groups.settings";

    // Step 1: Authorize -->
    String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId, redirectUrl, scope)
        .build();

    // Point or redirect your user to the authorizationUrl.
    System.out.println("Go to the following link in your browser:");
    System.out.println(authorizationUrl);

    // Read the authorization code from the standard input stream.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("What is the authorization code?");
    String code = in.readLine();
    // End of Step 1 <--

    // Step 2: Exchange -->
    AccessTokenResponse response = new GoogleAuthorizationCodeGrant(httpTransport, jsonFactory,
        clientId, clientSecret, code, redirectUrl).execute();
    // End of Step 2 <--

    GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
        response.accessToken, httpTransport, jsonFactory, clientId, clientSecret,
        response.refreshToken);

    Groupssettings service = new Groupssettings(httpTransport, accessProtectedResource, jsonFactory);
    service.setApplicationName("YOUR_APPLICATION_NAME");
    ...
  }
...

Python

Follow the setup intructions in the Python Quickstart.

PHP

Follow the setup intructions in the PHP Quickstart.

.NET

using System;
using System.Threading;
using System.Threading.Tasks;

using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Groupssettings.v1;
using Google.Apis.Groupssettings.v1.Data;
using Google.Apis.Services;

namespace GroupsSettings.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets
                {
                    ClientId = "CLIENT_ID_HERE",
                    ClientSecret = "CLIENT_SECRET_HERE",
                },
                new[] { GroupssettingsService.Scope.Groupssettings },
                "user",
                CancellationToken.None).Result;

            // Create the service.
            var service = new GroupssettingsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Group Settings API Sample",
            });

            ...
        }
    }
}

Send feedback about...

Groups Settings API
Groups Settings API