شما در حال مشاهده اسناد قدیمی برای Google Photos Library API هستید.
با REST شروع کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای شروع استفاده از Google Photos Library API، پروژه خود را با فعال کردن API از طریق Google API Console و تنظیم شناسه مشتری OAuth 2.0 پیکربندی کنید.
برنامه شما از طرف یک کاربر Google Photos با Google Photos تعامل دارد. به عنوان مثال، وقتی آلبومهایی را در کتابخانه Google Photos کاربر ایجاد میکنید یا موارد رسانه را در حساب Google Photos کاربر آپلود میکنید، کاربر این درخواستهای API را از طریق پروتکل OAuth 2.0 مجاز میکند.
شناسه مشتری OAuth 2.0 به کاربران برنامه شما اجازه می دهد تا وارد سیستم شوند، احراز هویت و در نتیجه از کتابخانه API استفاده کنند. کتابخانه API از حسابهای سرویس پشتیبانی نمیکند. برای استفاده از این API، کاربران باید به یک حساب Google معتبر وارد شوند.
API را فعال کنید
قبل از اینکه بتوانید از کتابخانه API استفاده کنید، باید آن را برای پروژه خود فعال کنید.
- به کنسول API Google بروید.
- از نوار منو، یک پروژه را انتخاب کنید یا یک پروژه جدید ایجاد کنید.
- برای باز کردن کتابخانه Google API، از منوی پیمایش، APIs & Services > Library را انتخاب کنید.
- «Google Photos Library API» را جستجو کنید. نتیجه صحیح را انتخاب کنید و روی Enable کلیک کنید.
شناسه مشتری OAuth 2.0 را درخواست کنید
برای درخواست شناسه مشتری OAuth و پیکربندی آن برای برنامه خود، مراحل زیر را دنبال کنید. این مثال از برنامهای استفاده میکند که در آن کل جریان OAuth در سمت سرور مدیریت میشود، مانند نمونههای ما. فرآیند راه اندازی ممکن است برای سایر سناریوهای پیاده سازی متفاوت باشد.
- به کنسول API Google بروید و پروژه خود را انتخاب کنید.
- از منو، APIs & Services > Credentials را انتخاب کنید.
- در صفحه اعتبارنامه ، روی ایجاد اعتبارنامه > شناسه مشتری OAuth کلیک کنید.
- نوع برنامه خود را انتخاب کنید. در این مثال، نوع برنامه کاربردی وب است.
مبداهایی را که برنامه شما از آنجا اجازه دسترسی به APIهای Google را دارد به شرح زیر ثبت کنید:
- برای شناسایی شناسه مشتری، یک نام وارد کنید.
در قسمت Authorized JavaScript origins ، مبدا برنامه خود را وارد کنید. این فیلد حروف عام را مجاز نمیداند.
میتوانید چندین منبع را وارد کنید تا به برنامهتان اجازه دهید روی پروتکلها، دامنهها یا زیر دامنههای مختلف اجرا شود. URL هایی که وارد می کنید مجاز به شروع درخواست OAuth هستند.
مثال زیر یک URL توسعه محلی (نمونه های ما localhost:8080
استفاده می کنند) و یک URL تولید را نشان می دهد.
http://localhost:8080
https://myproductionurl.example.com
قسمت Authorized Redirect URI نقطه پایانی است که پاسخها را از سرور OAuth 2.0 دریافت میکند. به طور معمول، این شامل محیط توسعه شما می شود و به مسیری در برنامه شما اشاره می کند.
http://localhost:8080/auth/google/callback
https://myproductionurl.example.com/auth/google/callback
روی ایجاد کلیک کنید.
از کادر گفتگوی مشتری OAuth، موارد زیر را کپی کنید:
برنامه شما میتواند با استفاده از این مقادیر به Google APIهای فعال دسترسی پیدا کند.
قبل از اینکه بتوانید یک برنامه عمومی را راه اندازی کنید که به کتابخانه API دسترسی دارد، برنامه شما باید توسط Google بررسی شود. هنگامی که برنامه خود را آزمایش می کنید، پیام "برنامه تایید نشده" روی صفحه ظاهر می شود تا زمانی که تأیید شود.
نمونه را امتحان کنید
اکنون که پروژه خود را برای استفاده با کتابخانه API پیکربندی کرده اید، برنامه نمونه را در GitHub بررسی کنید. برنامه نمونه نشان می دهد که چگونه می توانید یک قاب عکس هوشمند با استفاده از کتابخانه API بسازید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eTo use the Google Photos Library API, you must enable the API and set up an OAuth 2.0 client ID through the Google API Console.\u003c/p\u003e\n"],["\u003cp\u003eUsers must be signed in to a valid Google Account to use the Library API as it requires user authorization via OAuth 2.0 for actions like creating albums or uploading media.\u003c/p\u003e\n"],["\u003cp\u003eBefore launching publicly, your application needs to be reviewed and verified by Google to remove the "Unverified app" message during testing.\u003c/p\u003e\n"]]],["To utilize the Google Photos Library API, first enable it for your project in the Google API Console. Then, create an OAuth 2.0 client ID, specifying the application type, authorized JavaScript origins, and redirect URIs. Obtain the client ID and secret from the resulting dialog. Ensure your application is reviewed by Google before public launch. Note, only valid Google Account users can use this API as service accounts aren't supported.\n"],null,["# Get started with REST\n\nTo start using the Google Photos Library API, configure your project by enabling the API via\nthe 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, copy the following:\n\n - Client ID\n - Client secret\n\n Your app can access the enabled Google APIs using these values.\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\nTry out the sample\n------------------\n\nNow that you've configured your project for use with the Library API,\ncheck out the [sample app](/photos/library/samples) on GitHub. The sample app\ndemonstrates how you can build a smart photo frame using the Library API."]]