फ़िल्टर खोजें और लागू करें

अनुमति देने के ज़रूरी दायरे

Google Photos Library API में, मीडिया आइटम और एल्बम को ऐक्सेस करने के लिए कई स्कोप इस्तेमाल किए जाते हैं. अलग-अलग कॉल से लौटाए गए मीडिया आइटम, इस आधार पर अलग-अलग होते हैं कि डेवलपर ने किन दायरों का अनुरोध किया है.

photoslibrary.readonly का स्कोप, उपयोगकर्ता की लाइब्रेरी में मौजूद सभी मीडिया आइटम को ऐक्सेस करने की अनुमति देता है. photoslibrary.readonly.appcreateddata का स्कोप, सिर्फ़ उन मीडिया आइटम को ऐक्सेस करने की अनुमति देता है जिन्हें ऐप्लिकेशन ने बनाया है. ज़्यादा जानकारी के लिए, अनुमति के दायरे देखें.

उपलब्ध फ़िल्टर

किसी खास तरह के मीडिया के लिए, उपयोगकर्ता की लाइब्रेरी में खोज की जा सकती है. उदाहरण के लिए, हो सकता है कि आपको किसी खास दिन के लिए सिर्फ़ उन चीज़ों की ज़रूरत हो जो जानवरों की हैं या रसीदों की फ़ोटो को बाहर रखना चाहें. किसी एल्बम या लाइब्रेरी लिस्टिंग पर फ़िल्टर लागू करके कुछ ख़ास आइटम को बाहर रखा जा सकता है या उन्हें शामिल किया जा सकता है. मीडिया आइटम प्रॉपर्टी के आधार पर, पांच उपलब्ध फ़िल्टर होते हैं:

अगर albumId सेट है, तो mediaItems:search अनुरोध में फ़िल्टर का इस्तेमाल नहीं किया जाना चाहिए. अगर एल्बम आईडी सेट होने पर किसी फ़िल्टर का इस्तेमाल किया जाता है, तो INVALID_ARGUMENT गड़बड़ी (400) दिखती है.

नतीजों को, मीडिया आइटम को बनाए जाने के समय के हिसाब से क्रम में लगाया जाता है. तारीख के फ़िल्टर का इस्तेमाल करके, क्वेरी के लिए क्रम से लगाने के क्रम में बदलाव किया जा सकता है.

अपनी खोजों में अपलोड किए गए नए मीडिया को दिखने के लिए, थोड़ा समय दें. मीडिया फ़िल्टर न की गई खोजों में तुरंत दिखने लगता है.

ऐसे मीडिया आइटम जिनकी तारीख आगे की होती है वे फ़िल्टर की गई खोजों में नहीं दिखते. वे उन खोजों और एल्बम खोजों में दिखते हैं जिन्हें फ़िल्टर नहीं किया गया है.

फ़िल्टर लागू करना

फ़िल्टर लागू करने के लिए, mediaItems.search को कॉल करें और filter प्रॉपर्टी के बारे में बताएं.

आराम

यहां एक पोस्ट अनुरोध दिया गया है:

POST https://photoslibrary.googleapis.com/v1/mediaItems:search
Content-type: application/json
Authorization: Bearer oauth2-token
{
  "pageSize": "100",
  "filters": {
    ...
  }
}

पोस्ट अनुरोध करने पर यह रिस्पॉन्स मिलता है:

{
  "mediaItems": [
    ...
  ],
  "nextPageToken": "token-for-pagination"
}

Java

try {
  // Create a new Filter object
  Filters filters = Filters.newBuilder()
      // .setContentFilter(...)
      // .setDateFilter(...)
      // ...
      .build();

  // Specify the Filter object in the searchMediaItems call
  SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);
  for (MediaItem item : response.iterateAll()) {
    // ...
  }
} catch (ApiException e) {
  // Handle error
}

PHP

try {
    $filtersBuilder = new FiltersBuilder();
    // $filtersBuilder->addIncludedCategory(...);
    // $filtersBuilder->addDate(...);
    // ...
    // Make a search call with the options set in the filters builder
    $response = $photosLibraryClient->searchMediaItems(
        ['filters' => $filtersBuilder->build()]
    );
    foreach ($response->iterateAllElements() as $element) {
        // ...
    }
} catch (\Google\ApiCore\ApiException $e) {
    // Handle error
}

ज़्यादा जानकारी के लिए, लाइब्रेरी के कॉन्टेंट, एल्बम, और मीडिया आइटम की सूची बनाएं देखें.

सामग्री श्रेणियां

मीडिया वाले सभी आइटम प्रोसेस किए जाते हैं और उन्हें लेबल असाइन किए जाते हैं. इनमें से किसी भी कैटगरी को शामिल किया जा सकता है और उसे बाहर रखा जा सकता है.

ANIMALS FASHION LANDMARKS RECEIPTS WEDDINGS
ARTS FLOWERS LANDSCAPES SCREENSHOTS WHITEBOARDS
BIRTHDAYS FOOD NIGHT SELFIES  
CITYSCAPES GARDENS PEOPLE SPORT  
CRAFTS HOLIDAYS PERFORMANCES TRAVEL  
DOCUMENTS HOUSES PETS UTILITY  

काम की फ़ोटो में कई तरह के मीडिया कवर किए जाते हैं. आम तौर पर, इस कैटगरी में ऐसे आइटम शामिल होते हैं जिन्हें उपयोगकर्ता ने कुछ काम करने के लिए कैप्चर किया है. साथ ही, हो सकता है कि वह टास्क पूरा होने के बाद उपयोगकर्ता उनकी इच्छा न करे. इसमें दस्तावेज़, रसीद, स्क्रीनशॉट, स्टिकी नोट, मेन्यू, और मिलते-जुलते दूसरे मीडिया आइटम शामिल होते हैं.

ये कैटगरी सिर्फ़ Google Photos में मौजूद मिलते-जुलते लेबल जितनी ही सटीक होती हैं. कभी-कभी, आइटम पर गलत लेबल लगाए जा सकते हैं. इसलिए, हम इस बात की गारंटी नहीं देते कि कॉन्टेंट कैटगरी के फ़िल्टर कितने सटीक होंगे.

इसमें कैटगरी शामिल हैं

जब कई कैटगरी शामिल की जाती हैं, तो किसी भी कैटगरी से मेल खाने वाले मीडिया आइटम शामिल किए जाते हैं. हर अनुरोध के लिए, ज़्यादा से ज़्यादा 10 कैटगरी शामिल की जा सकती हैं. यह उदाहरण फ़िल्टर LANDSCAPES या LANDMARKS के किसी भी आइटम को दिखाता है.

आराम

{
  "filters": {
    "contentFilter": {
      "includedContentCategories": [
        "LANDSCAPES",
        "LANDMARKS"
      ]
    }
  }
}

Java

// Create a content filter that includes landmarks and landscapes
ContentFilter contentFilter = ContentFilter.newBuilder()
    .addIncludedContentCategories(ContentCategory.LANDMARKS)
    .addIncludedContentCategories(ContentCategory.LANDSCAPES)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setContentFilter(contentFilter)
    .build();
// Specify the Filter object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a content filter that includes landmarks and landscapes
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->addIncludedCategory(ContentCategory::LANDMARKS);
$filtersBuilder->addIncludedCategory(ContentCategory::LANDSCAPES);
// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

कैटगरी बाहर रखी जा रही हैं

सिर्फ़ वे मीडिया आइटम दिखाए जाते हैं जो बाहर रखी गई किसी भी कैटगरी से मेल नहीं खाते. शामिल की गई कैटगरी की तरह ही, हर अनुरोध के लिए ज़्यादा से ज़्यादा 10 कैटगरी को बाहर रखा जा सकता है.

यह फ़िल्टर ऐसे किसी भी आइटम को दिखाता है जो PEOPLE या SELFIES नहीं है:

आराम

{
  "filters": {
    "contentFilter": {
      "excludedContentCategories": [
        "PEOPLE",
        "SELFIES"
      ]
    }
  }
}

Java

// Create a content filter that excludes people and selfies
ContentFilter contentFilter = ContentFilter.newBuilder()
    .addExcludedContentCategories(ContentCategory.PEOPLE)
    .addExcludedContentCategories(ContentCategory.SELFIES)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setContentFilter(contentFilter)
    .build();
// Specify the Filter object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a content filter that excludes people and selfies
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->addExcludedCategory(ContentCategory::PEOPLE);
$filtersBuilder->addExcludedCategory(ContentCategory::SELFIES);
// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

कई कैटगरी शामिल और बाहर रखना

आपके पास कुछ कैटगरी को शामिल करने और अन्य को बाहर रखने का विकल्प होता है. यह उदाहरण LANDSCAPES और LANDMARKS दिखाता है, लेकिन ऐसे सभी मीडिया आइटम को हटा देता है जिनमें PEOPLE या SELFIES हों:

आराम

{
  "filters": {
    "contentFilter": {
      "includedContentCategories": [
        "LANDSCAPES",
        "LANDMARKS"
      ],
      "excludedContentCategories": [
        "PEOPLE",
        "SELFIES"
      ]
    }
  }
}

Java

// Create a content filter that excludes people and selfies and includes landmarks and landscapes
ContentFilter contentFilter = ContentFilter.newBuilder()
    .addIncludedContentCategories(ContentCategory.LANDSCAPES)
    .addIncludedContentCategories(ContentCategory.LANDMARKS)
    .addExcludedContentCategories(ContentCategory.PEOPLE)
    .addExcludedContentCategories(ContentCategory.SELFIES)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setContentFilter(contentFilter)
    .build();
// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a content filter that excludes people and selfies and includes landmarks and landscapes
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->addIncludedCategory(ContentCategory::LANDMARKS);
$filtersBuilder->addIncludedCategory(ContentCategory::LANDSCAPES);
$filtersBuilder->addExcludedCategory(ContentCategory::PEOPLE);
$filtersBuilder->addExcludedCategory(ContentCategory::SELFIES);
// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

तारीख और तारीख की सीमाएं

तारीख के फ़िल्टर, लौटाए गए नतीजों की तारीख को कुछ दिनों के लिए सीमित करते हैं. तारीख वाला फ़िल्टर दो तरीकों से तय किया जा सकता है: तारीख या सीमाएं. तारीखों और तारीखों का एक साथ इस्तेमाल किया जा सकता है. किसी भी तारीख या तारीख की सीमा से मेल खाने वाले मीडिया आइटम दिखाए जाते हैं. इसके अलावा, नतीजों को क्रम से लगाने के क्रम में बदलाव किया जा सकता है.

तारीख

तारीख में साल, महीना, और दिन शामिल होते हैं. ये फ़ॉर्मैट स्वीकार किए जाते हैं:

  • Year
  • साल, महीना
  • साल, महीना, दिन
  • महीना, दिन
  • महीना

अगर तारीख का कोई कॉम्पोनेंट खाली होता है या शून्य पर सेट होता है, तो उसे वाइल्डकार्ड माना जाता है. उदाहरण के लिए, अगर आपने दिन और महीना सेट किया है, लेकिन साल नहीं, तो किसी भी साल के उसी दिन और महीने से आइटम का अनुरोध किया जा रहा है:

आराम

{
  "filters": {
    "dateFilter": {
      "dates": [
        {
          "month": 2,
          "day": 15
        }
      ]
    }
  }
}

Java

// Create a new com.google.type.Date object using a builder
// Note that there are different valid combinations as described above
Date dayFebruary15 = Date.newBuilder()
    .setDay(15)
    .setMonth(2)
    .build();
// Create a new dateFilter. You can also set multiple dates here
DateFilter dateFilter = DateFilter.newBuilder()
    .addDates(dayFebruary15)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setDateFilter(dateFilter)
    .build();
// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new Google\Type\Date object with a day and a month
// Note that there are different valid combinations as described above
$dateFebruary15 = new Date();
$dateFebruary15->setDay(15);
$dateFebruary15->setMonth(2);
$filtersBuilder = new FiltersBuilder();
// Add the date to the filter. You can also set multiple dates here
$filtersBuilder->addDate($dateFebruary15);
// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

तारीख की सीमाएं

तारीख की सीमाएं, तारीखों की तुलना में ज़्यादा सुविधाएं देती हैं. उदाहरण के लिए, कई तारीखें जोड़ने के बजाय, तारीख की सीमा का इस्तेमाल करके महीने के दिनों का सेट देखा जा सकता है.

तारीख की सीमा में startDate और endDate होते हैं. ये दोनों सेट होने चाहिए. रेंज में हर तारीख के लिए, फ़ॉर्मैट की सीमाएं एक ही हैं. इनके बारे में तारीखें में बताया गया है. तारीखों का फ़ॉर्मैट एक ही होना चाहिए: अगर शुरू होने की तारीख एक साल और महीना है, तो खत्म होने की तारीख भी साल और महीना होनी चाहिए. इन सीमाओं को सभी के साथ लागू किया जाता है. साथ ही, शुरू और खत्म होने की तारीखें भी लागू किए गए फ़िल्टर में शामिल होती हैं:

आराम

{
  "filters": {
    "dateFilter": {
      "ranges": [
        {
          "startDate": {
            "year": 2014,
            "month": 6,
            "day": 12
          },
          "endDate": {
            "year": 2014,
            "month": 7,
            "day": 13
          }
        }
      ]
    }
  }
}

Java

// Create new com.google.type.Date objects for two dates
Date day2014June12 = Date.newBuilder()
    .setDay(12)
    .setMonth(6)
    .setYear(2014)
    .build();
Date day2014July13 = Date.newBuilder()
    .setDay(13)
    .setMonth(7)
    .setYear(2014)
    .build();
// Create a DateRange from these two dates
DateRange dateRange = DateRange.newBuilder()
    .setStartDate(day2014June12)
    .setEndDate(day2014July13)
    .build();
// Create a new dateFilter with the date range. You can also set multiple date ranges here
DateFilter dateFilter = DateFilter.newBuilder()
    .addRanges(dateRange)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setDateFilter(dateFilter)
    .build();
// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create two new Google\Type\Date objects
    $date2014June12 = new Date();
    $date2014June12->setDay(12);
    $date2014June12->setMonth(6);
    $date2014June12->setYear(2014);

    $date2014July13 = new Date();
    $date2014July13->setDay(13);
    $date2014July13->setMonth(7);
    $date2014July13->setYear(2014);

    // Add the two dates as a date range to the filter
    // You can also set multiple date ranges here
    $filtersBuilder = new FiltersBuilder();
    $filtersBuilder->addDateRange($date2014June12, $date2014July13);

    // Make a search call with the options set in the filters builder
    $response = $photosLibraryClient->searchMediaItems(
        ['filters' => $filtersBuilder->build()]
    );

तारीखें और तारीख की सीमाएं

एक ही समय पर कई तारीखों और तारीख की कई सीमाओं का इस्तेमाल किया जा सकता है. इन तारीखों में आने वाले आइटम, नतीजों में शामिल किए जाते हैं. अलग-अलग तारीखों और तारीख की सीमाओं के लिए, एक ही फ़ॉर्मैट का इस्तेमाल करना ज़रूरी नहीं है. हालांकि, अलग-अलग रेंज के शुरू और खत्म होने की तारीखें एक ही फ़ॉर्मैट में होती हैं:

आराम

{
  "filters": {
    "dateFilter": {
      "dates": [
        {
          "year": 2013
        },
        {
          "year": 2011,
          "month": 11
        }
      ],
      "ranges": [
        {
          "startDate": {
            "month": 1
          },
          "endDate": {
            "month": 3
          }
        },
        {
          "startDate": {
            "month": 3,
            "day": 24
          },
          "endDate": {
            "month": 5,
            "day": 2
          }
        }
      ]
    }
  }
}

Java

// Create a new com.google.type.Date object for the year 2013
Date day2013 = Date.newBuilder()
    .setYear(2013)
    .build();
// Create a new com.google.type.Date object for November 2011
Date day2011November = Date.newBuilder()
    .setMonth(11)
    .setYear(2011)
    .build();
// Create a date range for January to March
DateRange dateRangeJanuaryToMarch = DateRange.newBuilder()
    .setStartDate(Date.newBuilder().setMonth(1).build())
    .setEndDate(Date.newBuilder().setMonth(3).build())
    .build();
// Create a date range for March 24 to May 2
DateRange dateRangeMarch24toMay2 = DateRange.newBuilder()
    .setStartDate(Date.newBuilder().setMonth(3).setDay(24).build())
    .setEndDate(Date.newBuilder().setMonth(5).setDay(2).build())
    .build();
// Create a new dateFilter with the dates and date ranges
DateFilter dateFilter = DateFilter.newBuilder()
    .addDates(day2013)
    .addDates(day2011November)
    .addRanges(dateRangeJanuaryToMarch)
    .addRanges(dateRangeMarch24toMay2)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setDateFilter(dateFilter)
    .build();
// Specify the Filter object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new Google\Type\Date object for the year 2013
$date2013 = new Date();
$date2013->setYear(2013);

// Create a new Google\Type\Date object for November 2011
$dateNovember2011 = new Date();
$dateNovember2011->setMonth(11);
$dateNovember2011->setYear(2011);

$filtersBuilder = new FiltersBuilder();

// Create a date range for January to March
$filtersBuilder->addDateRange((new Date())->setMonth(1),
    (new Date())->setMonth(3));

// Create a date range for March 24 to May 2
$filtersBuilder->addDateRange((new Date())->setMonth(3)->setDay(24),
    (new Date())->setMonth(5)->setDay(2));

$filtersBuilder->addDate($date2013);
$filtersBuilder->addDate($dateNovember2011);

// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

मीडिया आइटम की सुविधाएं

फ़ीचर फ़िल्टर, नतीजों को सिर्फ़ उन आइटम तक सीमित करते हैं जिनमें खास सुविधाएं होती हैं. उदाहरण के लिए, जिन्हें Google Photos ऐप्लिकेशन में पसंदीदा के तौर पर मार्क किया गया है.

पसंदीदा

FeatureFilter में FAVORITES आइटम की सुविधा को शामिल करें, ताकि वे सिर्फ़ उन मीडिया आइटम को दिखा सकें जिन्हें उपयोगकर्ता ने पसंदीदा के तौर पर मार्क किया है:

आराम

{
  "filters" : {
    "featureFilter": {
      "includedFeatures": [
        "FAVORITES"
      ]
    }
  }
}

Java

// Create a new FeatureFilter for favorite media items
FeatureFilter featureFilter = FeatureFilter.newBuilder()
    .addIncludedFeatures(Feature.FAVORITES)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setFeatureFilter(featureFilter)
    .build();
// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new FeatureFilter for favorite media items
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->addIncludedFeature(Feature::FAVORITES);

// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

मीडिया प्रकार

खोज के नतीजों को, इस तरह के मीडिया के हिसाब से सीमित किया जा सकता है: फ़ोटो या वीडियो.

फ़ोटो

PHOTO, कई इमेज फ़ॉर्मैट में से कोई भी हो सकता है:

BMP JPG
GIF PNG
हाई इंटेंसिटी इंटरवल ट्रेनिंग (एचईआईसी) TIFF
ICO WebP

इसमें विशेष फ़ोटो प्रकार भी शामिल हैं, जैसे iOS लाइव फ़ोटो, मोशन फ़ोटो, पैनोरामा, फ़ोटो स्फ़ीयर, और VR फ़ोटो.

वीडियो

VIDEO अलग-अलग तरह के वीडियो फ़ॉर्मैट हो सकते हैं:

3जीपी एमएमवी
3G2 MOD
एएसएफ़ MOV
AVI MP4
डिवक्स MPG
एम2टी MTS
M2TS टीओडी
M4V WMV
MKV  

VIDEO में कुछ खास वीडियो फ़ॉर्मैट भी शामिल होते हैं, जैसे कि: वीआर वीडियो, स्लो-मोशन वीडियो, और Google Photos ऐप्लिकेशन में बनाए गए ऐनिमेशन.

यहां PHOTO के हिसाब से फ़िल्टर करने के उदाहरण दिए गए हैं:

आराम

{
  "filters": {
    "mediaTypeFilter": {
      "mediaTypes": [
        "PHOTO"
      ]
    }
  }
}

Java

// Create a new MediaTypeFilter for Photo media items
MediaTypeFilter mediaType = MediaTypeFilter.newBuilder()
    .addMediaTypes(MediaType.PHOTO)
    .build();
// Create a new Filters object
Filters filters = Filters.newBuilder()
    .setMediaTypeFilter(mediaType)
    .build();
// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new MediaTypeFilter for Photo media items
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->setMediaType(MediaType::PHOTO);

// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

एक से ज़्यादा मीडिया टाइप के फ़िल्टर नहीं जोड़े जा सकते.

उस डेटा को शामिल न करें जो ऐप्लिकेशन के ज़रिए नहीं बनाया गया है

उन मीडिया आइटम को बाहर करने के लिए जिन्हें आपके ऐप्लिकेशन ने नहीं बनाया है, excludeNonAppCreatedData फ़िल्टर सेट करें, जैसा कि इस उदाहरण में दिखाया गया है:

आराम

{
  "filters": {
    "excludeNonAppCreatedData": true
  }
}

Java

// Create a new Filters object that excludes media not created by your app
Filters filters = Filters.newBuilder()
    .setExcludeNonAppCreatedData(true)
    .build();

// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new Filters object that excludes media not created by your app
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->setExcludeNonAppCreatedData(true);

// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

ध्यान दें कि अगर .readonly.appcreateddata स्कोप का इस्तेमाल किया जा रहा है, तो इस फ़िल्टर को अनदेखा कर दिया जाता है.

संग्रहित की गई स्थिति

हो सकता है कि आपके उपयोगकर्ताओं ने अपनी कुछ फ़ोटो संग्रहित की हों. डिफ़ॉल्ट रूप से, संग्रहित फ़ोटो को खोजों में नहीं दिखाया जाता. संग्रहित आइटम को शामिल करने के लिए, फ़िल्टर में फ़्लैग सेट करें, जैसा कि नीचे दिए गए उदाहरण में दिखाया गया है:

आराम

{
  "filters": {
    "includeArchivedMedia": true
  }
}

Java

// Create a new Filters object that includes archived media
Filters filters = Filters.newBuilder()
    .setIncludeArchivedMedia(true)
    .build();

// Specify the Filters object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new Filters object that includes archived media
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->setIncludeArchivedMedia(true);

// Make a search call with the options set in the filters builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

फ़िल्टर संयोजित करना

अलग-अलग तरह के फ़िल्टर एक साथ इस्तेमाल किए जा सकते हैं. सिर्फ़ वे आइटम लौटाए जाते हैं जो अनुरोध की गई सभी सुविधाओं से मेल खाते हैं.

फ़िल्टर को मिलाते समय, हर फ़िल्टर टाइप के लिए फ़ॉर्मैटिंग से जुड़ी पाबंदियां वही होती हैं जब उन्हें अलग-अलग इस्तेमाल किया जाता है. इस उदाहरण में, सिर्फ़ वे फ़ोटो दिखाई गई हैं जिन्हें SPORT की कैटगरी में रखा गया है और जो 2014 या 2010 की हैं:

आराम

{
  "filters": {
    "contentFilter": {
      "includedContentCategories": [
        "SPORT"
      ]
    },
    "dateFilter": {
      "dates": [
        {
          "year": 2014
        },
        {
          "year": 2010
        }
      ]
    },
    "mediaTypeFilter": {
      "mediaTypes": [
        "PHOTO"
      ]
    }
  }
}

Java

// Create a new ContentFilter that only includes SPORT items
ContentFilter contentFilter = ContentFilter.newBuilder()
    .addIncludedContentCategories(ContentCategory.SPORT)
    .build();
// Create a new media type filter that only includes PHOTO media items
MediaTypeFilter mediaTypeFilter = MediaTypeFilter.newBuilder()
    .addMediaTypes(MediaType.PHOTO)
    .build();
// Create a new DateFilter that only includes items from 2010 or 2014
Date year2014 = Date.newBuilder().setYear(2014).build();
Date year2010 = Date.newBuilder().setYear(2010).build();
DateFilter dateFilter = DateFilter.newBuilder()
    .addDates(year2010)
    .addDates(year2014)
    .build();
// Create a new Filters object combining these filters
Filters filters = Filters.newBuilder()
    .setDateFilter(dateFilter)
    .setMediaTypeFilter(mediaTypeFilter)
    .setContentFilter(contentFilter)
    .build();
// Specify the Filter object in the searchMediaItems call
SearchMediaItemsPagedResponse response = photosLibraryClient.searchMediaItems(filters);

PHP

// Create a new ContentFilter
$filtersBuilder = new FiltersBuilder();
// Only include SPORT items
$filtersBuilder->addIncludedCategory(ContentCategory::SPORT);
// Only include PHOTO media items
$filtersBuilder->setMediaType(MediaType::PHOTO);
// Only include items from 2010 or 2014
$year2014 = new Date();
$year2014->setYear(2014);
$year2010 = new Date();
$year2010->setYear(2010);
$filtersBuilder->addDateRange($year2010, $year2014);

// Make a search call with the options set in the filters builder
// Filters have been combined in the filter builder
$response = $photosLibraryClient->searchMediaItems(
    ['filters' => $filtersBuilder->build()]
);

नतीजों को क्रम से लगाना

सिर्फ़ तारीख के फ़िल्टर का इस्तेमाल करने वाली क्वेरी को क्रम से लगाया जा सकता है.

अगर आपने क्रम से लगाने का विकल्प नहीं चुना है, तो आपके नतीजे घटते क्रम में (नए से पुराने के क्रम में) क्रम में दिखेंगे.

इस टेबल में, orderBy पैरामीटर के लिए इस्तेमाल किए जा सकने वाले विकल्प दिखाए गए हैं:

orderBy पैरामीटर
MediaMetadata.creation_time desc मीडिया आइटम को घटते क्रम में दिखाता है (सबसे नए आइटम पहले)
MediaMetadata.creation_time मीडिया आइटम को बढ़ते क्रम में दिखाता है (सबसे पुराने आइटम पहले)

इस उदाहरण में 2017 के सभी मीडिया आइटम दिखाए गए हैं. इसमें सबसे पुराना और सबसे नया आइटम दिखाया गया है.

आराम

{
  "filters": {
    "dateFilter": {
      "dates": [
        {
          "year": 2017
        }
      ]
    }
  },
  "orderBy": "MediaMetadata.creation_time"
}

Java

// Create a new dateFilter for the year 2017.
DateFilter dateFilter = DateFilter.newBuilder()
        .addDates(Date.newBuilder().setYear(2017))
        .build();

// Create a new Filters object
Filters filters = Filters.newBuilder()
        .setDateFilter(dateFilter)
        .build();

// Sort results by oldest item first.
final OrderBy newestFirstOrder = OrderBy.MEDIAMETADATA_CREATION_TIME;

// Specify the filter and sort order in the searchMediaItems call.
SearchMediaItemsPagedResponse response
        = photosLibraryClient.searchMediaItems(filters, newestFirstOrder);

PHP

// Create a new dateFilter for the year 2017.
$filtersBuilder = new FiltersBuilder();
$filtersBuilder->addDate((new Date())->setYear(2017));

// Make a search call with the options set in the filters builder and sort
// the results by oldest item first.
$response = $photosLibraryClient->searchMediaItems(
    [
        'filters' => $filtersBuilder->build(),
        'orderBy' => OrderBy::MEDIAMETADATA_CREATION_TIME
    ]
);