Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Commit

Permalink
Accommodate PR comments.
Browse files Browse the repository at this point in the history
Especially, remove "bookshelf-dotnet" and pull the project name from the service account json file.
  • Loading branch information
SurferJeffAtGoogle committed May 26, 2017
1 parent 00a53bc commit 74c8889
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Google API C++ Client

The current installation has only been tested on Unix/Linux systems.
This release does not support Windows yet. The following sequence of
The current installation has only been tested on Unix/Linux systems;
this release does not support Windows yet. The following sequence of
actions should result in a turnkey build of the client libraries from
the source code given only:

Expand All @@ -13,10 +13,6 @@ the source code given only:
* C++ compiler and Make
- Mac OSX https://developer.apple.com/xcode/
- Linux http://gcc.gnu.org/
* CMake
- Either http://www.cmake.org/cmake/resources/software.html
- or run ./prepare_dependencies.py cmake
and restart your shell to get the updated path.

### Build Steps:

Expand Down
8 changes: 4 additions & 4 deletions prepare_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,10 @@ def __init__(self, config, restricted_package_names):
# Mongoose is used as webserver for samples.
# The ownership and license style seems to keep changing, so we do not
# download it by default.
'mongoose': (MongoosePackageInstaller(
config,
'https://github.com/cesanta/mongoose/archive/6.7.zip',
'mongoose-6.7')),
# 'mongoose': (MongoosePackageInstaller(
# config,
# 'https://github.com/cesanta/mongoose/archive/6.7.zip',
# 'mongoose-6.7')),

'curl': (CurlPackageInstaller(
config, 'https://github.com/curl/curl/releases/download/curl-7_54_0/curl-7.54.0.tar.gz')),
Expand Down
3 changes: 3 additions & 0 deletions src/googleapis/client/auth/oauth2_service_authorization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ util::Status OAuth2ServiceAccountFlow::InitFromJsonData(
GetStringAttribute(data, "private_key", &private_key_);
VLOG(4) << "private_key: " << private_key_.substr(0, 40) << "...";

GetStringAttribute(data, "project_id", &project_id_);
VLOG(4) << "project_id: " << project_id_;

return StatusOk();
}

Expand Down
6 changes: 6 additions & 0 deletions src/googleapis/client/auth/oauth2_service_authorization.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class OAuth2ServiceAccountFlow : public OAuth2AuthorizationFlow {
*/
const string& client_email() const { return client_email_; }

/*
* Returns the project_id contained in the service account json file.
*/
const string& project_id() const { return project_id_; }

/*
* Sets the path of a Pkcs12 private key (typically from the API console).
*
Expand Down Expand Up @@ -94,6 +99,7 @@ class OAuth2ServiceAccountFlow : public OAuth2AuthorizationFlow {
string client_email_;
string private_key_; // typically disjoint with p12_path_
string p12_path_; // typically disjoint with private_key_
string project_id_;

googleapis::util::Status MakeJwt(const string& claims, string* jwt) const;
DISALLOW_COPY_AND_ASSIGN(OAuth2ServiceAccountFlow);
Expand Down
26 changes: 15 additions & 11 deletions src/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ billing.
deployment, access control, billing, and services.
1. Open the [Cloud Platform Console](https://console.cloud.google.com/).
2. In the drop-down menu at the top, select **Create a project**.
3. Click **Show advanced options**. Under App Engine location, select a
United States location.
4. Give your project a name.
5. 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.
Expand All @@ -43,8 +41,10 @@ credentials to authenticate with the Cloud Storage API.
2. **Download credentials**.

1. [Visit the API Manager Dashboard](https://console.cloud.google.com/apis/dashboard)
and click **Credentials**.
and click **Credentials** in the left navigation.

2. Click **Create credentials** and choose **Service Account key**.

3. 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.
Expand All @@ -66,9 +66,13 @@ you (your Google Cloud Project), and the user.

1. **Enable APIs.**

Visit the [Google Cloud Console API Manager](
https://console.cloud.google.com/apis/api/calendar-json.googleapis.com/overview)
and click **Enable** to enable the Google Calendar API.
1. Visit the [Google Cloud Console API Manager](
https://console.cloud.google.com/apis).

2. Under **G Suite APIs**, click **Calendar API**.

3. Click **Enable** to enable the Google Calendar API.


2. **Download credentials**.

Expand Down Expand Up @@ -108,7 +112,7 @@ you (your Google Cloud Project), and the user.
(or restore from an earlier run) then enter a Google Email Address.
Otherwise just press return.
Address:
Address: [PRESS ENTER]
Enter the following URL into a browser:
https://accounts.google.com/o/oauth2/auth?client_id=19279605555-2gdkn11eoiq3m1st0p4ilv6mqqm3rir1.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar&response_type=code
Expand All @@ -120,12 +124,12 @@ you (your Google Cloud Project), and the user.
SAMPLE: Showing Initial Calendars
==== CalendarList ====
CalendarListEntry
ID: XXX@google.com
Summary:XXX@google.com
ID: XXX@gmail.com
Summary:XXX@gmail.com
CalendarListEntry
ID: YYY@google.com
Summary: YYY@google.com
ID: YYY@gmail.com
Summary: YYY@gmail.com
SAMPLE: Adding Calendar
Expand Down
6 changes: 3 additions & 3 deletions src/samples/storage_sample_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using google_storage_api::StorageService;
using client::HttpTransport;
using client::HttpTransportLayerConfig;
using client::OAuth2Credential;
using client::OAuth2AuthorizationFlow;
using client::OAuth2ServiceAccountFlow;
#if HAVE_OPENSSL
using client::OpenSslCodecFactory;
#endif
Expand All @@ -80,7 +80,7 @@ class StorageSample {

OAuth2Credential credential_;
std::unique_ptr<StorageService> storage_;
std::unique_ptr<OAuth2AuthorizationFlow> flow_;
std::unique_ptr<OAuth2ServiceAccountFlow> flow_;
std::unique_ptr<HttpTransportLayerConfig> config_;
};

Expand Down Expand Up @@ -116,7 +116,7 @@ util::Status StorageSample::Startup(int argc, char* argv[]) {
void StorageSample::Run() {
credential_.set_flow(flow_.get());
google_storage_api::BucketsResource_ListMethod request(
storage_.get(), &credential_, "bookshelf-dotnet");
storage_.get(), &credential_, flow_->project_id());
Json::Value value;
google_storage_api::Buckets buckets(&value);
auto status = request.ExecuteAndParseResponse(&buckets);
Expand Down

0 comments on commit 74c8889

Please sign in to comment.