Random Background from Pinterest

Since Apple brought back the ability to set the wallpaper via Shortcuts I got to work on a few ideas. One of which was to grab an image from a random pin on a Pinterest board.

At first, it looked bleak; they no longer provide access tokens and I couldn’t find any information on when that might come back. I did however, find an SO article that showed a promising link to the widget API you can create on the Pinterest Developer dashboard.

Which looks like so:

https://widgets.pinterest.com/v3/pidgets/boards/<USERNAME>/<BOARD>/pins/

Applying that to my own username and board it returns the following…

Summary
{
  "code": 0,
  "data": {
    "user": {
      "profile_url": "https://www.pinterest.com/eightysixmail/",
      "about": "",
      "location": "",
      "image_small_url": "https://s.pinimg.com/images/user/default_60.png",
      "pin_count": 475,
      "id": "349451389744767106",
      "follower_count": 20,
      "full_name": "Jeremiah Fischer"
    },
    "pins": [
      {
        "aggregated_pin_data": {
          "aggregated_stats": {
            "saves": 2352,
            "done": 0
          }
        },
        "pinner": {
          "profile_url": "https://www.pinterest.com/eightysixmail/",
          "about": "",
          "location": "",
          "image_small_url": "https://s.pinimg.com/images/user/default_60.png",
          "pin_count": 475,
          "id": "349451389744767106",
          "follower_count": 20,
          "full_name": "Jeremiah Fischer"
        },
        "board": {
          "name": "City Art",
          "image_thumbnail_url": "https://i.pinimg.com/upload/349451321026062399_board_thumbnail_2021-03-07-04-02-02_78003_60.jpg",
          "url": "/eightysixmail/city-art/",
          "follower_count": 3,
          "pin_count": 73,
          "id": "349451321026062399",
          "description": ""
        },
        "attribution": null,
        "id": "349451252344724252",
        "dominant_color": "#408d8d",
        "description": " ",
        "is_video": false,
        "images": {
          "237x": {
            "width": 237,
            "height": 313,
            "url": "https://i.pinimg.com/237x/9a/ff/dd/9affddb89385c8824ec17512c1c356b6.jpg"
          },
          "564x": {
            "width": 564,
            "height": 745,
            "url": "https://i.pinimg.com/564x/9a/ff/dd/9affddb89385c8824ec17512c1c356b6.jpg"
          }
        },
        "story_pin_data": null,
        "embed": null,
        "domain": "artstation.com",
        "repin_count": 0,
        "link": "https://www.artstation.com/artwork/581lnw",
        "native_creator": null
      }
    ]
  },
  "message": "ok",
  "endpoint_name": "v3_pidget_get_user_pins",
  "status": "success"
}

I reduced the number of entries for demo purposes.

This link will return no more than 50 records (0-49). It is completely public and (other than the full name from the profile) no personally identifiable information can be discerned. Any username and board will work. No API keys or limits to worry about.

Knowing this information, I have separated out my pins that are background worthy into separate boards limiting them to 50 pins a piece.

Here’s the breakdown of the Shortcut by action:

  1. Create a list of Pinterest users and board names
  2. Pick a random item from the list
  3. Format the URL with the board name selected from above
  4. Get a Dictionary from the contents of the URL
  5. Drill into the relevant pins array (Which, will be only 50 records max)
  6. Get a random pin entry from the above dictionary
  7. Drill into the pin entry and find the largest image (should always be “564x”)
  8. Get the contents of the URL for the image
  9. Set a wallpaper (In my case, the lock screen w/o the preview)

This setup allows you to add as many pin boards as you want. Each username you provide can have any number of boards, and each board can have 50 pins. Thus, creating an infinite combination.

I also went a step further and created some Personal Automations to give me a new random background every hour.

I’m really happy with it and thought I would share!

1 Like