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.
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.
Click here to enable the Google Cloud Storage API for your project.
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.
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.
Visit the Google Cloud Console API Manager.
Under G Suite APIs, click Calendar API.
Click Enable to enable the Google Calendar API.
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.
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.
Pass the client secret file path to
$ 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: XXX@gmail.com Summary:XXX@gmail.com CalendarListEntry ID: YYY@gmail.com Summary: YYY@gmail.com SAMPLE: Adding Calendar Added new calendar IDemail@example.com: Calendar ID: firstname.lastname@example.org Summary: Calendar added by CalendarSample ... Done!