Google My Business API Samples

repository·master·Indexed 40 days ago

https://github.com/google/google-my-business-samples

A collection of code samples, demonstrations, and tools for integrating with the Google My Business API. Includes implementation guides and client library setup for .NET (Google.Apis.MyBusinessAccountManagement.v1), Java, PHP, and Python.

Tokens
1.7K
Snippets
8
Records
14
Agent score
50%

What's inside Google My Business

  1. Access Google My Business API Samples

    master

    This repository provides samples, demos, and tools for interacting with the Google My Business API. Samples are organized by programming language in their respective directories.

    Note on Versions: This repository contains the latest samples. If you specifically require v4 samples, you must use the v4 branch of the repository.

    https://github.com/google/google-my-business-samples/tree/v4
  2. Install the Google API Python Client

    master

    To use the Python samples, you need to install the google-api-python-client and oauth2client libraries. It is recommended to use a virtual environment to manage these dependencies.

    Follow these steps to set up your environment:

    1. Install virtualenv.
    2. Create and activate a new virtual environment.
    3. Install the required Google API libraries.
    pip install virtualenv
    virtualenv myenv
    source myenv/bin/activate
    myenv/bin/pip install google-api-python-client oauth2client
  3. Build and Run Java Samples in Eclipse

    master

    To build and run the Java samples, follow these steps using Eclipse with the Buildship Gradle integration plugin:

    1. Create a Gradle project.
    2. Add the required dependencies to your build.gradle file.
    3. Set your JAVA_HOME in Gradle properties (in Eclipse: Window > preferences).
    4. Place your Java source file in src/main/java.
    5. Execute the build task under Gradle Tasks.
    6. Run the application by right-clicking the Java file and selecting Run As > Java Application.
    dependencies {
        compile 'com.google.apis:google-api-services-mybusinessaccountmanagement:v1-rev20210217-1.31.0'
        compile 'com.google.oauth-client:google-oauth-client-jetty:1.31.0'
        implementation 'com.google.code.gson:gson:2.8.6'
    }
  4. Set up client secrets for .NET authentication

    master

    Before running samples, you must configure OAuth 2.0 credentials:

    1. Create a Client ID: In the Google Cloud Platform Console, create a Client ID.
    2. Download Credentials: Download the JSON file associated with your Client ID.
    3. Configure File: Create a file named client_secrets.json in the same directory as your source files and paste the contents of the downloaded JSON there.
    4. Set Redirect URI: For local testing, set the authorized redirect URI to http://127.0.0.1/authorize/ in your Google Cloud Console settings.
  5. Install the Google API PHP Client

    master

    To use the Google My Business API in PHP, you must install the google/apiclient library using Composer.

    Note: The following commands assume you are setting up Composer locally in a bin directory if it is not already installed.

    wget -O composer-setup.php https://getcomposer.org/installer
    mkdir bin
    php composer-setup.php --install-dir=bin --filename=composer
    php bin/composer require google/apiclient:"^2.9.1"
  6. Use the Account Management API client library for .NET

    master

    To interact with Google My Business Account Management, use the official Google API client library for .NET. You can find the generated library on NuGet or via the official library reference.

    NuGet Package: Google.Apis.MyBusinessAccountManagement.v1

    # Install via NuGet
    dotnet add package Google.Apis.MyBusinessAccountManagement.v1
  7. Build and run .NET My Business samples

    master

    To run the .NET samples in Visual Studio, follow these steps:

    1. Install NuGet Packages: Search for and install the following packages via the NuGet Package Manager:
      • Google.Apis.MyBusinessAccountManagement
      • Google.Apis.Auth
    2. Add Source: Add the sample source code to your project.
    3. Build and Run: Build the solution and execute the project.
    # Required NuGet packages
    Google.Apis.MyBusinessAccountManagement
    Google.Apis.Auth
  8. Run Python API samples

    master

    The samples utilize the sample_tools utility from the Google APIs Python client. This utility builds an API service from a downloaded discovery document and handles user authentication via OAuth.

    To test the setup, run the accounts_list.py sample within your activated virtual environment. If successful, you will be able to list your Google My Business accounts and locations.

    python accounts_list.py