Google 포토 라이브러리 API의 기존 문서를 보고 계신 것입니다.
PHP 클라이언트 라이브러리 시작하기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
PHP 클라이언트 라이브러리로 Google 포토 라이브러리 API를 사용하려면 다음을 수행해야 합니다.
개발 환경에서 클라이언트 라이브러리를 설정합니다.
그 전에 API를 사용 설정하여 프로젝트를 구성합니다.
OAuth 2.0 클라이언트 ID를 설정할 수 있습니다.
애플리케이션은
Google 포토 사용자입니다. 예를 들어 사용자의
Google 포토 라이브러리에 추가하거나 미디어 항목을
Google 포토 계정에서 사용자는
OAuth 2.0 프로토콜
OAuth 2.0 클라이언트 ID를 사용하면 애플리케이션 사용자가
Library API를 사용하세요 Library API는
서비스 계정 이 API를 사용하려면 유효한 Google 계정에 로그인해야 합니다.
계정.
API 사용 설정
라이브러리 API를 사용하려면 우선 프로젝트에서 사용 설정해야 합니다.
- Google API 콘솔로 이동합니다.
- 메뉴 바에서 프로젝트를 선택하거나 새 프로젝트를 만듭니다.
- Google API 라이브러리를 열려면 탐색 메뉴에서
API 및 서비스 > Library로 구성됩니다.
- 'Google 포토 라이브러리 API'를 검색합니다. 올바른 결과를 선택하고
사용 설정.
OAuth 2.0 클라이언트 ID 요청
아래 단계에 따라 OAuth 클라이언트 ID를 요청하고
애플리케이션입니다. 이 예에서는 전체 OAuth 흐름이
서버 측에서 처리되는 것을 볼 수 있습니다. 설정 프로세스는 다를 수 있음
자세한 내용은 구현 시나리오를 참고하세요.
- Google API 콘솔로 이동합니다.
프로젝트를 선택합니다
- 메뉴에서 API 및 서비스 > 사용자 인증 정보.
- 사용자 인증 정보 페이지에서 사용자 인증 정보 만들기 >를 클릭합니다. OAuth 클라이언트 ID를 입력합니다.
- 애플리케이션 유형을 선택합니다. 이 예에서 애플리케이션 유형은
웹 애플리케이션.
앱이 Google API에 액세스할 수 있는 출처를 등록합니다.
방법은 다음과 같습니다.
- 클라이언트 ID를 식별하기 위해 이름을 입력합니다.
승인된 JavaScript 원본 필드에 파일의 원본을 입력합니다.
있습니다. 이 필드에는 와일드 카드가 허용되지 않습니다.
앱이 다양한 출처에서 실행되도록 허용할 출처를 여러 개 입력할 수 있습니다.
하위 도메인일 수 있습니다. 입력한 URL은
OAuth 요청을 시작할 수 있습니다.
다음 예는 로컬 개발 URL을 보여줍니다 (샘플은
localhost:8080
) 및 프로덕션 URL이 포함됩니다.
http://localhost:8080
https://myproductionurl.example.com
승인된 리디렉션 URI 필드는
응답을 수신할 수 있습니다. 일반적으로 여기에는
애플리케이션의 경로를 가리킵니다.
http://localhost:8080/auth/google/callback
https://myproductionurl.example.com/auth/google/callback
만들기를 클릭합니다.
-
표시되는 OAuth 클라이언트 대화상자에서 JSON 파일을 다운로드합니다.
클라이언트 구성이 포함됩니다 클라이언트 세부정보는
있습니다.
이 JSON 파일은 나중에 설정하는 데 사용됩니다.
이 클라이언트 라이브러리에서 작동하는 PHP용 Google 인증 라이브러리를 사용할 수 있습니다.
라이브러리 API에 액세스하는 공개 애플리케이션을 실행하려면 먼저
Google의 검토를 받아야 합니다. '확인되지 않은 앱' 메시지가 표시되는
화면에 완전히 표시되며
인증됨
클라이언트 라이브러리 설정
PHP 클라이언트 라이브러리는 모든 백엔드 API 호출을 자동으로 처리하고
일반적인 API 작업을 위한 코드 샘플을 비롯하여 작업할 수 있는 친숙한 객체를 제공합니다.
먼저, PHP용 Google 포토 라이브러리 API 클라이언트 라이브러리를
GitHub의 종속 항목을 설치합니다.
그런 다음 PHP용 OAuth2 사용자 인증 정보를 설정합니다.
다운로드 옵션
composer 사용
라이브러리를 개발 환경에 종속 항목으로 포함합니다. 먼저
다음 명령어를 사용하여 프로젝트 구성에 라이브러리를 추가하고
vendor/
디렉터리에 복사합니다.
composer require google/photos-library
또는 다음을 수행할 수도 있습니다.
인스턴스를
저장소 또는
압축된 파일로
tarball을 사용합니다.
PHP용 OAuth2 사용자 인증 정보 설정
이 클라이언트 라이브러리는
Google 인증 라이브러리
PHP 자세한 내용은
Google API 클라이언트 라이브러리에 OAuth 2.0 사용
PHP
설정 시 인증 라이브러리에서 반환한 사용자 인증 정보 사용
PhotosLibraryClient
샘플 사용해 보기
PHP 클라이언트 라이브러리를 사용하여 첫 번째 API 호출을 하려면 아래 코드를 시도해 보세요.
use Google\Auth\Credentials\UserRefreshCredentials;
use Google\Photos\Library\V1\PhotosLibraryClient;
use Google\Photos\Library\V1\PhotosLibraryResourceFactory;
try {
// Use the OAuth flow provided by the Google API Client Auth library
// to authenticate users. See the file /src/common/common.php in the samples for a complete
// authentication example.
$authCredentials = new UserRefreshCredentials( /* Add your scope, client secret and refresh token here */ );
// Set up the Photos Library Client that interacts with the API
$photosLibraryClient = new PhotosLibraryClient(['credentials' => $authCredentials]);
// Create a new Album object with at title
$newAlbum = PhotosLibraryResourceFactory::album("My Album");
// Make the call to the Library API to create the new album
$createdAlbum = $photosLibraryClient->createAlbum($newAlbum);
// The creation call returns the ID of the new album
$albumId = $createdAlbum->getId();
} catch (\Google\ApiCore\ApiException $exception) {
// Error during album creation
} catch (\Google\ApiCore\ValidationException $e) {
// Error during client creation
echo $exception;
}
이 외에도
GitHub의 샘플
시도해 볼 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-29(UTC)
[null,null,["최종 업데이트: 2025-08-29(UTC)"],[[["\u003cp\u003eTo use the Google Photos Library API with PHP, enable the API, request an OAuth 2.0 client ID, and set up the PHP client library.\u003c/p\u003e\n"],["\u003cp\u003eUsers must sign in with a Google Account as the API does not support service accounts, requiring OAuth 2.0 for authorization.\u003c/p\u003e\n"],["\u003cp\u003eSet up your OAuth2 credentials by configuring a web application in Google API Console with authorized origins and redirect URIs.\u003c/p\u003e\n"],["\u003cp\u003eDownload and install the Google Photos Library API client library for PHP using composer or by cloning the repository.\u003c/p\u003e\n"],["\u003cp\u003eAuthenticate users using the Google Auth Library for PHP, then utilize the PhotosLibraryClient to interact with the API and access its features.\u003c/p\u003e\n"]]],["To use the Google Photos Library API with PHP, first, enable the API in the Google API Console and create an OAuth 2.0 client ID, specifying your app's authorized JavaScript origins and redirect URIs. Download the client ID's JSON file, containing the client ID and secret. Next, install the PHP client library via Composer, and set up OAuth2 credentials using the downloaded JSON file. Use these credentials to set up the `PhotosLibraryClient` and try API calls.\n"],null,["# Get started with PHP client library\n\nTo start using the Google Photos Library API with the PHP client library, you will need to\n[set up the client library](#get-library) in your development environment.\nBefore you do that, [configure your project](#configure-app) by enabling the API\nvia the Google API Console and setting up an OAuth 2.0 client ID.\n\nYour application interacts with Google Photos on behalf of a\nGoogle Photos user. For instance, when you create albums in a user's\nGoogle Photos library or upload media items to a user's\nGoogle Photos account, the user authorizes these API requests via the\n[OAuth 2.0](/identity/protocols/OAuth2) protocol.\n\nThe OAuth 2.0 client ID allows your application users to sign in, authenticate,\nand thereby use the Library API. The Library API does not support\nservice accounts; to use this API, users must be signed in to a valid Google\nAccount.\n\nConfigure your app\n------------------\n\n### Enable the API\n\nBefore you can use the Library API, you must enable it for your project.\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library).\n2. From the menu bar, select a project or create a new project.\n3. To open the Google API Library, from the Navigation menu, select **APIs \\& Services \\\u003e Library**.\n4. Search for \"Google Photos Library API\". Select the correct result and click **Enable**.\n\n### Request an OAuth 2.0 client ID\n\nFollow the steps below to request an OAuth client ID and configure it for your\napplication. This example uses an application where the entire OAuth flow is\nhandled server-side, such as the one in our samples. The setup process may vary\nfor other [implementation scenarios](/identity/protocols/OAuth2).\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library) and select your project.\n2. From the menu, select **APIs \\& Services \\\u003e Credentials**.\n3. On the **Credentials** page, click **Create Credentials \\\u003e OAuth client ID**.\n4. Select your **Application type** . In this example, the application type is **Web application**.\n5. Register the origins from which your app is allowed to access the Google APIs\n as follows:\n\n 1. To identify the client ID, enter a name.\n 2. In the **Authorized JavaScript origins** field, enter the origin for your\n app. This field doesn't allow wildcards.\n\n You can enter multiple origins to allow your app to run on different\n protocols, domains, or subdomains. The URLs you enter are allowed to\n start an OAuth request.\n\n The following example shows a local development URL (our samples use\n `localhost:8080`) and a production URL. \n\n http://localhost:8080\n https://myproductionurl.example.com\n\n 3. The **Authorized redirect URI** field is the endpoint that receives\n responses from the OAuth 2.0 server. Typically, this includes your\n development environment and points to a path in your application.\n\n http://localhost:8080/auth/google/callback\n https://myproductionurl.example.com/auth/google/callback\n\n 4. Click **Create**.\n\n\u003c!-- --\u003e\n\n6. From the resulting OAuth client dialog, download the JSON file\n containing your client configuration. You client details consist of the\n following:\n\n - Client ID\n - Client secret\n\n This JSON file will be used later to [set up](#get-library)\n the Google Auth library for PHP which works with this client library.\n\nBefore you can launch a public application that accesses the Library API,\nyour app must be reviewed by Google. An \"Unverified app\" message appears on the\nscreen when you test your application, until it is\n[verified](https://support.google.com/cloud/answer/7454865).\n\nSet up the client library\n-------------------------\n\nThe PHP client library handles all the backend API calls for you, and exposes\nfriendly objects to work with, including code samples for some common API tasks.\nFirstly, download and install the Google Photos Library API client library for PHP along with\nthe dependencies from [GitHub](https://github.com/google/php-photoslibrary).\nThen, set up your OAuth2 credentials for PHP.\n\n### Download options\n\nUse [composer](https://github.com/google/php-photoslibrary#using-composer-require)\nto include the library as a dependency in your development environment. Run the\nfollowing command to add the library to your project configuration and download\nit to the `vendor/` directory. \n\n composer require google/photos-library\n\nAlternatively, you can also\n[clone the\nrepository](https://github.com/google/php-photoslibrary#using-git-clone) or\n[download a compressed\ntarball](https://github.com/google/php-photoslibrary#downloading-a-compressed-tarball).\n\n### Set up your OAuth2 credentials for PHP\n\nThis client library works with the\n[Google Auth Library for\nPHP](https://github.com/google/google-auth-library-php). For more information,\nrefer to [Using OAuth 2.0 with the Google API Client Library for\nPHP](https://developers.google.com/api-client-library/php/auth/web-app).\n\nUse the authentication credentials returned by the auth library when setting up\nthe `PhotosLibraryClient`.\n\nTry out some samples\n--------------------\n\nTry the code below to make your first API call using the PHP client library. \n\n use Google\\Auth\\Credentials\\UserRefreshCredentials;\n use Google\\Photos\\Library\\V1\\PhotosLibraryClient;\n use Google\\Photos\\Library\\V1\\PhotosLibraryResourceFactory;\n\n try {\n // Use the OAuth flow provided by the Google API Client Auth library\n // to authenticate users. See the file /src/common/common.php in the samples for a complete\n // authentication example.\n $authCredentials = new UserRefreshCredentials( /* Add your scope, client secret and refresh token here */ );\n\n // Set up the Photos Library Client that interacts with the API\n $photosLibraryClient = new PhotosLibraryClient(['credentials' =\u003e $authCredentials]);\n\n // Create a new Album object with at title\n $newAlbum = PhotosLibraryResourceFactory::album(\"My Album\");\n\n // Make the call to the Library API to create the new album\n $createdAlbum = $photosLibraryClient-\u003ecreateAlbum($newAlbum);\n\n // The creation call returns the ID of the new album\n $albumId = $createdAlbum-\u003egetId();\n } catch (\\Google\\ApiCore\\ApiException $exception) {\n // Error during album creation\n } catch (\\Google\\ApiCore\\ValidationException $e) {\n // Error during client creation\n echo $exception;\n }\n\nThere are more\n[samples](https://github.com/google/php-photoslibrary/tree/samples) on GitHub\nfor you to try."]]