Tuesday 23 September 2014

Playing with the Pinterest 'sort-of' API

Yesterday's lunchtime coding gave me the desire to want to download the pins from some of my pinterest boards and be able to store the links and a high-quality version of the images. It's great collecting some of these inspirations - I'm particularly interested in lino-prints and watercolour journals and wanted to put them in a place where I could work with them for some of my own ideas.

So, I did a bit of googling and came across some informative posts. First was a good set of pointers from Ben Wong on StackOverflow which detailed the following openly available services:

https://api.pinterest.com/v3/pidgets/users/[username]/pins/

https://api.pinterest.com/v3/pidgets/boards/[username]/[board_name]/pins/

http://api.pinterest.com/v3/pidgets/pins/info/?pin_ids=521150988102375972

and another inferred one:

https://api.pinterest.com/v3/pidgets/boards/[username]/

which gives a list of a user's boards.

Bashing out a bit of code to call these URLs and get the results wasn't too much trouble. These all return JSON formatted data, so I used some of the code from my previous posting to walk through the responses. In the case of requesting the pins for a particular board the result looks something like this (this isn't actually my data):

The overall envelope details the board and list of pins.....


{
  "status": "success", 
  "code": 0, 
  "host": "ngapi2-485c0b18", 
  "generated_at": "Tue, 23 Sep 2014 13:07:44 +0000", 
  "message": "OK", 
  "data": 
  {
    "pins": 
    [

    ], 
    "user": 
    {
       "about": "", 
       "location": "", 
       "full_name": "hondrou", 
       "follower_count": 13, 
       "image_small_url": "http://passets-ec.pinterest.com/images/user/default_30.png", 
       "pin_count": 969, 
       "id": "482800159961391892", 
       "profile_url": "http://www.pinterest.com/hondrou/"}, 
       "board": 
       {
          "description": "", 
          "url": "/honrdrou/board/", 
          "follower_count": 8, 
          "image_thumbnail_url": "http://media-cache-ak0.pinimg.com/upload/482800091241943111_board_thumbnail_2014-09-13-20-51-23_20940_60.jpg", 
          "pin_count": 166, 
          "id": "482800091241943111",     
          "name": "board"
      }
   }
}

And then for each of the pins:

 {
"attribution": null, 
"description": "descriptive text", 
"pinner": 
 {
 "about": "", 
 "location": "", 
 "full_name": "hondrou", 
 "follower_count": 12, 
 "image_small_url": "http://passets-ec.pinterest.com/images/user/default_30.png",  
 "pin_count": 947, 
 "id": "482800159961391111", 
 "profile_url": "http://www.pinterest.com/hondrou/"}, 
 "repin_count": 0, 
 "dominant_color": "#5d5b36", 
 "like_count": 0, 
 "link": "http://bitacoradefrida.blogspot.com.ar/blahblahblah.html", 
 "images": 
 {
  "237x": 
  {
   "url": "http://media-cache-ak0.pinimg.com/237x/2e/7e/9f/2e7e9f14100b9acb832f047364a37111.jpg", 
   "width": 237, 
   "height": 201
  }
 }, 
 "embed": null, 
 "is_video": false, 
 "id": "48280002252727911"
}

Which is all good and pretty easy to parse using a fragment below:


string json = GetJSON(String.Format("https://api.pinterest.com/v3/pidgets/boards/hondrou/{0}/pins/",board));

JavaScriptSerializer jss = new JavaScriptSerializer();
jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() });
DynamicJsonConverter.DynamicJsonObject j = jss.Deserialize(json, typeof(object)) as DynamicJsonConverter.DynamicJsonObject; //dynamic;

dynamic d = jss.Deserialize(json, typeof(object)) as dynamic;

foreach (dynamic b in d.data.pins)
{
    Pin pin = new Pin();
    pin.description = b.description;
    pin.link = b.link;

    dynamic c = b.images["237x"];
    pin.image = b.images["237x"].url;

This was all going very nicely until I took a look at the images that were downloaded. These appear only to reference the 237x size images which were too low quality for what I wanted. Hmmph, shame.

I did quite a bit more googling and didn't get anywhere. So, it's good that Pintrest sort of have some API, but a bit of a shame it is so lacking in functionality.

Unfortunately I couldn't go any further with this as the other bit of work I wanted to do was to download and reference a list of the pins from the pin that I had pinned.. eh? Well, take for example a particular pin I made for a person's journal. Typically they then pin a whole lot of pages and I wanted to follow that in full, but didn't want to pin each on of the individual images.

Unfortunately the API (even getting the information for a particular pin) just references the pinner details as my own details (I know them already, thank you!), not the pinner I pined from. Nor does there seem to be any way of getting the associated pins to that particular pin, so no way to find the other journal pages.

Seems like some of these functions are available via an API and were available previously with V2 of the API but have been blocked and now require an API key. It seems Pintrest are very reluctant to give these out and if my own experience of getting an early account (I was a very early Pinterest adopter) are anything to go by I can believe it. What a shame.

4 comments:

  1. Hey Hondou.
    Thanks for that post.
    Just figured out, that u can get the original image size by replacing the in your case "237x" with "originals".
    736x is a size that also works with all of the images that i have tested

    ReplyDelete
  2. Hi Reto,

    Thank you very much for commenting on the post. That's great! I just checked it as well and works like a dream. I'm going to update my Swift posting on doing this on the Mac as well as I've just tried it there.

    Hondrou

    ReplyDelete
  3. You can actually go up to 1200x, and it will return the largest pic in the cache up to that.

    ReplyDelete
  4. The credit for my successful Pinterest account goes to PinPinterest. I used to spend a lot of time on Pinterest and still, I was not able to get a decent amount of followers. For the first time, I used PinPinterest for my Pinterest account automation, and it became the savior of my sinking account. Within a few weeks, I got a lot of active followers, thanks to PinPinterest.

    ReplyDelete