ספריות לקוח של Agent Platform Workbench

בדף הזה מוסבר איך להתחיל להשתמש בספריות הלקוח של Cloud ל-Notebooks API. ספריות לקוח מאפשרות לגשת בקלות לממשקי ה-API שלGoogle Cloud בשפה נתמכת. אמנם אפשר להשתמש ישירות בממשקי ה-API שלGoogle Cloud על ידי יצירת בקשות גולמיות חדשות לשרת, אבל ספריות לקוח מפשטות את התהליך ומפחיתות באופן משמעותי את כמות הקוד שתצטרכו לכתוב.

מידע נוסף על ספריות הלקוח ב-Cloud ועל ספריות הלקוח הישנות יותר של Google API זמין במאמר הסבר על ספריות לקוח.

התקנת ספריית הלקוח

C++

ב-GitHub README מפורטות הדרישות של ספריית הלקוח הזו, ומוסבר איך להתקין יחסי תלות.

C#

Install-Package Google.Cloud.Notebooks.V1 -Pre

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-C# ‎.

Go

go get cloud.google.com/go/notebooks

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-Go.

Java

אם משתמשים ב-Maven, צריך להוסיף את הקוד הבא לקובץ pom.xml. במאמר העוסק בספריות BOM ל-Google Cloud Platform תוכלו לקרוא מידע נוסף על עצי מוצרים (BOM).

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.90.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-notebooks</artifactId>
  </dependency>
</dependencies>

אם משתמשים ב-Gradle, צריך להוסיף את הקוד הבא ליחסי התלות:

implementation platform('com.google.cloud:libraries-bom:26.90.0')

implementation 'com.google.cloud:google-cloud-notebooks'

אם משתמשים ב-sbt, צריך להוסיף את הקוד הבא ליחסי התלות:

libraryDependencies += "com.google.cloud" % "google-cloud-notebooks" % "1.98.0"

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-Java.

Node.js

npm install @google-cloud/notebooks

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-Node.js.

PHP

composer require google/cloud

מידע נוסף זמין במאמר שימוש ב-PHP ב-Google Cloud.

Python

Mac/Linux

pip install virtualenv
virtualenv ENVIRONMENT_NAME
source ENVIRONMENT_NAME/bin/activate
ENVIRONMENT_NAME/bin/pip install google-cloud-notebooks

Windows

pip install --upgrade google-cloud-notebooks
pip install virtualenv
virtualenv ENVIRONMENT_NAME
ENVIRONMENT_NAME\Scripts\activate
ENVIRONMENT_NAME\Scripts\pip.exe install google-cloud-notebooks

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-Python.

Ruby

gem install google-cloud-notebooks

מידע נוסף זמין במאמר הגדרת סביבת פיתוח ב-Ruby.

מגדירים אימות

כדי לאמת קריאות לממשקי ה-API של Google Cloud , ספריות הלקוח תומכות ב-Application Default Credentials ‏ (ADC). בספריות מתבצע חיפוש של פרטי כניסה בקבוצה של מיקומים מוגדרים, והמערכת משתמשת בפרטי הכניסה האלה כדי לאמת בקשות ל-API. בעזרת ADC, פרטי הכניסה לאפליקציה יכולים להיות זמינים בסביבות שונות, כמו בפיתוח מקומי או בייצור, בלי שיהיה צריך לשנות את קוד האפליקציה.

בסביבות ייצור, הגדרת ADC משתנה בהתאם לשירות ולהקשר. מידע נוסף זמין במאמר בנושא הגדרה של Application Default Credentials.

בסביבת פיתוח מקומית, אפשר להגדיר ADC עם פרטי הכניסה שמשויכים לחשבון Google:

  1. התקינו את ה-CLI של Google Cloud ואז היכנסו ל-CLI של gcloud באמצעות הזהות המאוחדת שלכם. אחרי שנכנסתם לחשבון, אתחלו את ה-CLI של Google Cloud באמצעות הפקודה הבאה:

    gcloud init
  2. יוצרים פרטי כניסה לאימות מקומי בחשבון המשתמש:

    gcloud auth application-default login

    אם מופיעה שגיאת אימות, ודאו ש נכנסתם ל-CLI של gcloud באמצעות הזהות המאוחדת שלכם.

    מסך הכניסה יופיע. אחרי שנכנסים, פרטי הכניסה נשמרים בקובץ פרטי הכניסה המקומי שמשמש את ADC.

שימוש בספריית הלקוח

בדוגמאות הבאות מוסבר איך להשתמש בספריית הלקוח בחלק מהשפות הזמינות.

C++

// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! [all]
#include "google/cloud/notebooks/v2/notebook_client.h"
#include "google/cloud/location.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
    return 1;
  }

  auto const location = google::cloud::Location(argv[1], argv[2]);

  namespace notebooks = ::google::cloud::notebooks_v2;
  auto client = notebooks::NotebookServiceClient(
      notebooks::MakeNotebookServiceConnection());

  for (auto i : client.ListInstances(location.FullName())) {
    if (!i) throw std::move(i).status();
    std::cout << i->DebugString() << "\n";
  }

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;
}
//! [all]

Node.js

// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

async function main(projectId, location) {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'my-project';
  // const location = 'global';

  // Imports the Google Cloud Some API library
  const {NotebookServiceClient} = require('@google-cloud/notebooks');
  const client = new NotebookServiceClient();
  async function listInstances() {
    const [instances] = await client.listInstances({
      parent: `projects/${projectId}/locations/${location}`,
    });
    for (const instance of instances) {
      console.info(`instance: ${instance.name}`);
    }
  }
  listInstances();
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
  console.error(err.message);
  process.exitCode = 1;
});

מקורות מידע נוספים

C++

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של C++‎:

C#

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של ‎#C:

Go

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של Go:

Java

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח ל-Java:

Node.js

ברשימה הבאה מופיעים קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של Node.js:

PHP

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של PHP:

Python

ברשימה הבאה מופיעים קישורים למקורות מידע נוספים שקשורים לספריית הלקוח של Python:

Ruby

ברשימה הבאה יש קישורים למקורות מידע נוספים שקשורים לספריית הלקוח ל-Ruby: