A collection of samples that demonstrate how to call some Google Cloud services from C++.
See the instructions in the root README to build.
Before calling a Google API, you must create a Google Cloud project and enable billing.
-
Create a project in the Google Cloud Platform Console. If you haven't already created a project, create one now. Projects enable you to manage all Google Cloud Platform resources for your app, including deployment, access control, billing, and services.
- Open the Cloud Platform Console.
- In the drop-down menu at the top, select Create a project.
- Give your project a name.
- Make a note of the project ID, which might be different from the project name. The project ID is used in commands and in configurations.
-
Enable billing for your project. If you haven't already enabled billing for your project, enable billing now. Enabling billing allows the application to consume billable resources such as running instances and storing data.
The Cloud Storage sample uses Service Account credentials to authenticate with the Cloud Storage API.
-
Enable APIs.
Click here to enable the Google Cloud Storage API for your project.
-
Download credentials.
-
Visit the API Manager Dashboard and click Credentials in the left navigation.
-
Click Create credentials and choose Service Account key.
-
Under Service account, choose Compute Engine default service account, and leave JSON selected under Key Type. Click Create. A .json file will be downloaded to your computer.
-
-
Run storage_sample.
Pass the path of the .json file you downloaded to the storage_sample:
$ bin/storage_sample path/to/service_account.json https://www.googleapis.com/storage/v1/b/1gallon https://www.googleapis.com/storage/v1/b/2gallon https://www.googleapis.com/storage/v1/b/5gallon Done!
The calendar sample uses 3-legged authentication. The 3 parties are Google, you (your Google Cloud Project), and the user.
-
Enable APIs.
-
Visit the Google Cloud Console API Manager.
-
Under G Suite APIs, click Calendar API.
-
Click Enable to enable the Google Calendar API.
-
-
Download credentials.
-
Visit the Google Cloud Console Credentials page.
-
Click Create credentials.
-
Choose OAuth client ID.
-
For Application type, choose Other.
-
For Name, type Calendar console application.
-
Click Create.
-
The Google Cloud Console will display your client ID and client secret in a window. Click OK to close the window.
-
You should now see
Calendar console application
listed under Oauth 2.0 client IDs. Click the down arrow icon to download a client secret file.
-
-
Run calendar_sample.
Pass the client secret file path to
calendar_sample
.$ bin/calendar_sample path/to/client_secret.json SAMPLE: Getting User Authorization Welcome to the Google APIs for C++ CalendarSample. You will need to authorize this program to look at your calendar. If you would like to save these credentials between runs (or restore from an earlier run) then enter a Google Email Address. Otherwise just press return. Address: [PRESS ENTER] Enter the following URL into a browser: https://accounts.google.com/o/oauth2/auth?client_id=xyz.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar&response_type=code Enter the browser's response to confirm authorization: 4/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Authorized SAMPLE: Showing Initial Calendars ==== CalendarList ==== CalendarListEntry ID: [email protected] Summary:[email protected] CalendarListEntry ID: [email protected] Summary: [email protected] SAMPLE: Adding Calendar Added new calendar ID=google.com_8537hv9v85d50m5jtct09u4ndo@group.calendar.google.com: Calendar ID: [email protected] Summary: Calendar added by CalendarSample ... Done!
- See LICENSE