Get list of all files in Google Photos

两盒软妹~` 提交于 2019-12-21 04:59:06

问题


My ultimate goal is to get a list with all the files (photos, videos) in my Google Photos account preferably with their path.

If I have to use some API I would rather use a .NET based one. Can you provide some directions in this matter?

I've tried the Gdata API, via the PicasaService, but providing my email/password as credentials did not work and I always get 404 response.


回答1:


How to list all files in your Google Photos:

I was surprised at how long it took me to find this API. It's not necessarily "secret information", but I suppose most users are perfectly happy viewing their Google Photos "the old fashioned way". My initial goal was to be able to determine which photos had/had not properly uploaded before I risk deleting anything as valuable as even my "3rd backup copy" of old photos.

  • Like so many things in life, there's an easy way and a hard way.

  • Depending on your point of view, the hard way is often more fun and/or more fulfilling...


Short Answer: (The "Easy" Way)

  1. Make sure you're logged into your Google Account on your "usual" (default) browser.

  2. Click this:

      https://picasaweb.google.com/data/feed/api/user/default

You'll get a text-based list of all your Google Photos Albums. Both the album list and the photo list look suspiciously like RSS Feeds (and can be bookmarked as such if you should so desire).


I know you don't want to copy your list of photos manually, but I suspect others that come across this question want the "easy" way:

  • After opening the API URL, click the first album link.

  • hit Ctrl+A then Ctrl+C to copy text from the page

  • go to your favorite text editor (Notepad++, Excel, oldschool Notepad, etc) and hit Ctrl+V

  • go back to the photo list, click your browser's

    Back button and repeat for each album.

Authentication: For the sake of simplicty, first make sure you are signed in to your Google account from any Google page, such as from the top-right corner of the Google Search page. This will allow you to use the generic addresses listed below -- otherwise the word "default" would need to be replaced with your Google ID, as as well as other changes to accomodate Google API Authentication.


API Endpoints

If you have a preferred method of sending GET requests then all you'll need is two URL's.

As I understand it, all Google Photos are stored in Albums (even if they don't appear to be). Therefore, in order to list all photos, you must parse all of your albums, listing the photos in each one.

The GET call to list your Google Photos albums is:

https://picasaweb.google.com/data/feed/api/user/default

The GET call to list all photos within an album is:

https://picasaweb.google.com/data/feed/api/user/default/albumid/__[albumID]__

Retrieving the List Programmatically: (The ".NET API" Way)

.NET Example from Google:

PhotoQuery query = new PhotoQuery(PicasaQuery.CreatePicasaUri(username, albumid));

PicasaFeed feed = service.Query(query);

foreach (PicasaEntry entry in feed.Entries)
{
    Console.WriteLine(entry.Title.Text);
}

★ The string "default" can be used in place of a real username, in which case the server will use the username of the current user credentials used to authenticate the request.

More Info: Google Picasa .NET Developer's Guide: Request a List of Photos


List all Google Photos using VBA: (The"Web-Scrapey Way" with Excel)

Excel has built-in XML-Parsing functionality, in various forms:

  • Import XML Data (Developer Tab) Excel 2007+
  • Connect to an XML file (Power Query) Excel 2010+
  • Webservice & FilterXML (Worksheet Functions) Excel 2013+

...but not even the newest features seem to support enough [of what I assume to be] variations in XML style/source, to be of use to me... (or maybe I'm just doing something wrong.

Thus, my preferred method for parsing XML is to simply load it into a String with an HttpRequest and then use Instr and Mid to locate the values I'm interested in. It's messy, but I've used it as a "quick fix" to retrieve several types of data from several types of sites.

While writing this answer I seem to have misplaced my related code (side effect of over-multitasking?!) -- but if you made it this far, you probably get the gist of it. The simple function for retrieving the source from a URL is below. If you're interested in seeing the rest, add a comment and I'll look harder. :-)

Public Function getHTTP(ByVal url As String) As String
'equivalent to Excel's WEBSERVICE function
    Dim encResp() As Byte, xmlHTTP As Object
    Set xmlHTTP = CreateObject("MSXML2.XMLHTTP") 'create XML/HTTP object
    xmlHTTP.Open "GET", url, False 'initialize GET request
    xmlHTTP.send 'send request to remote server
    encResp = xmlHTTP.responseBody 'receive raw (encoded) response
    Set xmlHTTP = Nothing 'always clean up after yourself!
    getHTTP = StrConv(encResp, vbUnicode) 'return decoded response
End Function

Also a sneaky way to quickly count occurrences of one string within another:

Function countOccur(searchWithin As String, toFind As String) As String
    'returns the count of occurrences of [toFind] within [searchWithin]
    countOccur = UBound(Split(searchWithin, toFind))
End Function

Counting occurrences of <entry> on an album or photo page returns the count of albums or photos on that page.


Related Links:

  • Picasa Web Albums Data API Reference

  • MSDN : About Native XMLHTTP

  • Using Microsoft's XMLHTTP Object to Get Data From Other Web Pages

  • MSDN : responseBody Property (IXMLHTTPRequest)




回答2:


If you want to list all your photos and check them against your backups you could use my python project https://pypi.org/project/gphotos-sync/ which uses the new(ish) Google Photos API.

This will:-

  • index all of your media and albums into a SQL database
  • download a local backup (if required)
  • make a comparison of your new local backup against previous backups
  • give you a list of the files missing from your library
  • give you a list of files missing from your previous backups
  • give you a list of all the duplicates in your backup folders

Note that the comparison works on metadata in the files themselves and the folder structure and filenames need not match for it to work.




回答3:


I thought this was much easier:

Here's my bash script:

#!/bin/bash
#
# listgp - list google photos
#
# usage: listgp <file>
#
# dumps listing of all curreent user's stored google photos in the speeceifieed file
#
# example access to google api
#
# curl   'https://photoslibrary.googleapis.com/v1/mediaItems?pageToken=CkQKQnR5cGUuZ29vZ2xlYXBpcy5jb20vZ29vZ2xlLnBob3Rvcy5saWJyYXJ5LnYxLkxpc3RNZWRpYUl0ZW1zUmVxdWVzdBKiAUFIX3VRNDM0V1JKaEVkcTRfYU1uUXNnUXlzdGJpUEt4enlhVXZ3QW1TUTB5cVg2SEdRRk85MjkwRlFrRVg2VlJMRVBOVnI4cHRyRWhPcE11bTN3WUFTVHNnTXNFdmc5eUtaODd6TFJsLXh2QjNnSUlabWpLZl9sZV81c2lMc1VCUmhsalNFRXowWm9lazVhczQtNXB0dkJtYzduYUs1b1Vidw'   --header 'Authorization: Bearer ya29.GmTMBkWYE5CNTCSKJJTqlSh7FohUHp6u0hWTiyevsIW5iEGbBC0lmExfCNAldH8kaKBkwszW3Pk-ZwAzFMPNXtM4RlBF8M4vgbf8Lzv99LiVxWtojooSnRxOHWqq7ZEm-4sE9NI-'   --header 'Accept: application/json'  --compressed
#
# to determine your auth token,
#    see https://developers.google.com/photos/library/reference/rest/v1/mediaItems/list
# open dev tools in chrome, go to network tab, run the example, log into your google photos account
#    you can inpect the headers and find one that has 'Authorization: Bearer '.  Copy and paste your token
#    in the script below as the value for 'auth'.
#
#
auth="ya29.GmPNBqtRiw1dvOdiqjoaRkG9CtO2gunFtV8u_00vsAHROatuT5gZlFwNjmXf-CiPxOqxdgDKmweTdZIXeOCVaMM7d8n7E9VQlxAKOZo1zyE5Gq0_Nqqpc7T6csUJ5wablvhajQw"
#
function getItems() {
    pageToken=$1;

    if [ "$pageToken" != "" ]
    then
       pageTokenParam=pageToken="$pageToken";
    else    
    pageTokenParam="";
    fi

    curl  \
     "https://photoslibrary.googleapis.com/v1/mediaItems?$pageTokenParam" \
     --header "Authorization: Bearer $auth" \
     --header 'Accept: application/json'\
     --compressed > page

    cat page >> list

    grepOut=(`grep nextPageToken page | sed s/\"//g`)

    if [ "${grepOut[0]}" == "" ]
    then
    exit;
    fi

    getItems ${grepOut[1]}
}

getItems



回答4:


How to list all media items from specific albums or whole library

Deprecated Picasa API alternative

Since Picasa API has been deprecated by Google, the Google Photos API can be used to obtain information about albums and to get a list of photos and videos in that album, or even in the whole Google Photos library.

This can be done using REST, Java or PHP (as listed on their examples page).

Get started: https://developers.google.com/photos/


Web API provided by Google

You can also easily test API functionality without downloading or coding anything, by visiting one of the API method links on the web shown on the examples page:

  • List albums: https://developers.google.com/photos/library/reference/rest/v1/albums/list
    • This way you can obtain albumId parameters from all albums in your Google Photos library.
  • List media items: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/list
    • This way you can list ALL media items in your Google Photos library.
  • List shared albums: https://developers.google.com/photos/library/reference/rest/v1/sharedAlbums/list
    • This way you can list only albums that you've shared or have been shared with you.

In order to obtain a list of all photos and videos in a specific album, use:

  • Search media items: https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search
    • This way you can list media items from one album.
    • Using this method you can only list at most 100 media items in an album at a time (on one page). Each response gives you the nextPageToken at the end. Use the pageToken parameter to navigate through pages.
    • If you need to do this a couple of times, no problem. For simple and repeating tasks like this, you can utilize TinyTask to record mouse and keyboard input, and automate the boring work.

Note

For simple searches and listing, you can use the above mentioned web API that gives at most 100 results per page. For anything more advanced I advise you to write code that will go through all result pages and store or print out the information that you need. For a no coding solution, TinyTask is a good alternative.




回答5:


Try this way:

  1. Select all photos you have in account. You may have trouble if you have lots of them, to workaround so select the first one and scroll down. The images will load, holding shift button makes hover images under cursor, so click on images with shift to select as much as possible.
  2. When you have necessary selection, click download images. The file starts to download. Your task is to interrupt it and try to get into saved file with some archive viewer. The file is corrupted, but at least the archive will contain all file names.


来源:https://stackoverflow.com/questions/36871477/get-list-of-all-files-in-google-photos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!