חיפוש והחלה של מסננים

היקפי ההרשאות הנדרשים

ה-Google Photos Library API כולל מספר היקפים שמשמשים לגישה לפריטי מדיה ולאלבומים. פריטי המדיה שמוחזרים מקריאות שונות משתנים בהתאם להיקפי ההרשאות שהתבקשו על ידי המפתח.

ההיקף photoslibrary.readonly מאפשר גישה לכל פריטי המדיה בספריית המשתמש. ההיקף של photoslibrary.readonly.appcreateddata מאפשר גישה רק לפריטי מדיה שהאפליקציה יצרה. מידע נוסף זמין בהיקפי ההרשאות.

מסננים זמינים

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

אין להשתמש במסננים בבקשת mediaItems:search אם השדה albumId מוגדר. אם נעשה שימוש במסנן כשה-אלבום Id מוגדר, תוחזר השגיאה INVALID_ARGUMENT (400).

התוצאות ממוינות לפי מועד היצירה של פריט המדיה. אפשר לשנות את סדר המיון של שאילתות באמצעות מסנני תאריכים.

מומלץ להמתין זמן מה עד שמדיה חדשה שהעליתם תופיע בחיפושים. המדיה תופיע מיד בחיפושים בלי סינון.

פריטי מדיה שיש להם תאריך בעתיד לא יופיעו בחיפושים מסוננים. הם מופיעים בחיפושים לא מסוננים ובאלבומים.

החלת מסנן

כדי להחיל מסנן, צריך לקרוא לפונקציה mediaItems.search ולציין את המאפיין filter.

REST

זוהי בקשת POST:

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

בקשת ה-POST מחזירה את התגובה הבאה:

{
  "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.

REST

{
  "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:

REST

{
  "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:

REST

{
  "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()]
);

תאריכים וטווחי תאריכים

מסנני תאריכים מגבילים את התאריך של התוצאות שמוחזרות לקבוצת ימים מסוימת. יש שתי דרכים לציין מסנן תאריכים: תאריכים או טווחים. אפשר להשתמש בתאריכים ובטווחים יחד. מוחזרים פריטי מדיה שתואמים לאחד מהתאריכים או מטווחי התאריכים. אפשר לשנות את סדר המיון של התוצאות.

התאריכים

תאריך מכיל שנה, חודש ויום. אפשר להשתמש בפורמטים הבאים:

  • שנה
  • שנה, חודש
  • שנה, חודש, יום
  • יום, חודש
  • חודש

כאשר רכיב של תאריך ריק או מוגדר לאפס, הוא נחשב כתו כללי לחיפוש. לדוגמה, אם הגדרתם את היום והחודש אבל לא את השנה, אתם צריכים לבקש פריטים מאותו יום ובאותו חודש בכל שנה:

REST

{
  "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, וצריך להגדיר את שניהם. לכל תאריך בטווח יש אותן מגבלות פורמט שמתוארות בקטע תאריכים. התאריכים חייבים להיות באותו פורמט: אם תאריך ההתחלה הוא שנה וחודש, תאריך הסיום חייב להיות גם שנה וחודש. הטווחים מוחלים כולל, ותאריכי ההתחלה והסיום כלולים במסנן שהוחל:

REST

{
  "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()]
    );

שילוב תאריכים וטווחי תאריכים

אפשר להשתמש בכמה תאריכים ובכמה טווחי תאריכים בו-זמנית. פריטים הכלולים באחד מהתאריכים האלה נכללים בתוצאות. תאריכים וטווחי תאריכים נפרדים לא חייבים להיות בפורמט זהה, אבל תאריכי ההתחלה והסיום של טווחי תאריכים נפרדים כן:

REST

{
  "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.

מועדפים

כוללים את תכונת הפריטים FAVORITES ב-FeatureFilter כדי להחזיר רק פריטי מדיה שהמשתמש סימן כמועדפים:

REST

{
  "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
HEIC TIFF
ICO WEBP

הוא כולל גם סוגים מיוחדים של תמונות, כמו תמונות חיות ב-iOS, תמונות עם תנועה, פנורמה, תמונות פנורמיות ב-360° ותמונות VR.

וידאו

אפשר להשתמש בVIDEO בפורמטים שונים של וידאו:

3GP MMV
3G2 מתמר
ASF MOV
‎.AVI MP4
DIVX MPG
M2T MTS
M2TS TOD
M4V ‎.WMV
MKV  

VIDEO כולל גם פורמטים מיוחדים של וידאו, כמו סרטוני VR, סרטונים בהילוך איטי ואנימציות שנוצרו באפליקציית Google Photos.

המסננים הבאים לדוגמה מאת PHOTO:

REST

{
  "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 כפי שמוצג בדוגמה הבאה:

REST

{
  "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, המערכת מתעלמת מהמסנן הזה.

מצב שהועבר לארכיון

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

REST

{
  "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()]
);

שילוב מסננים

אפשר לשלב בין סוגים שונים של מסננים. יוחזרו רק פריטים שתואמים לכל התכונות שהתבקשו.

כשמשלבים מסננים, הגבלות הפורמט על כל סוג מסנן זהות לשימוש בכל מסנן בנפרד. בדוגמה הבאה מוחזרות רק תמונות משנת 2014 או מ-2010 שסווגו כ-SPORT:

REST

{
  "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, ומציגה את הפריטים הישנים ביותר תחילה ואת החדשים ביותר אחרונים.

REST

{
  "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
    ]
);