14

This was requested in 1 and declined because of a missing authentication method.

Now that authentication is in place, is there a way to retrieve the favorited tags of a user (myself)?

2

2 Answers 2

2

UPDATE: The feature appears to be present in the, so far, undocumented API version 2.3. See captncraig's answer on this page.


After all these years, it looks like this might never get implemented. However, it's not too hard to get the information via page scraping.

  1. From a browser or scraper that is logged in as the user, fetch the site's question page. (EG: http://stackapps.com/questions)

  2. Parse the #interestingTags > a.post-tag nodes.

For example, this javascript will work in the browser console while logged in to and browsing any Stack Exchange page:

var favTagNodes = $('<div><a class="post-tag">** Error loading favorite tags. **</a></div>') 
.load ("/questions #interestingTags>a.post-tag", function (response, status, xhr) {
    var favoriteTags    = favTagNodes.find ("a.post-tag").map ( function () {
        return this.textContent;
    } )
    .get ();

    console.log ("favoriteTags: ", favoriteTags);
} );

  1. It can be made into a bookmarklet, or userscript, or browser extension.

  2. It even works cross-domain when using GM_xmlhttpRequest and a full URL.

  3. Be sure to cache the results for at least an hour to avoid excessive scrapes of the page and possible banning. See also: Etiquette of Screen-scraping Stack Overflow?.

1

Good news! The (yet undocumented) api version 2.3 has this feature.

https://api.stackexchange.com/2.3/users/{id}/tag-preferences?access_token=...&key=...&site=StackOverflow.com will give you something like:

{
  "items": [
    {
      "tag_preference_type": "favorite_tag",
      "user_id": 9999999,
      "tag_name": "git"
    }, {
      "tag_preference_type": "favorite_tag",
      "user_id": 9999999,
      "tag_name": "go"
    }, {
      "tag_preference_type": "ignored_tag",
      "user_id": 9999999,
      "tag_name": "java"
    }
    ... 
  ],
  "has_more": false,
  "quota_max": 10000,
  "quota_remaining": 9997
}
1
  • Confirmed. Note that api.stackexchange.com/2.3/users/me/tag-preferences does not yet work. May 4, 2017 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .