tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
109 stars 27 forks source link

How do I work with the versions of the site that still use window.Tumblr (uppercase)? #100

Closed taracdia closed 1 year ago

taracdia commented 1 year ago

I need the old equivalent of window.Tumblr.apifetch and googling it has not helped me find it. In a nutshell I'm trying to get the uuid of a blog from the page of the blog itself and I can't just use the new window.tumblr.apifetch because it uses the old version. So I need either a way to do that or some help finding the documentation for the old stuff so that I can find it myself. Thank you!

marcustyphoon commented 1 year ago

I didn't really work on the core of the legacy XKit core, but if I recall correctly it was using the undocumented/private "svc" tumblr endpoints via its Nx_XHR helper. I wouldn't recommend copying any of its code because there are so many outdated (ie. bad) layers of abstraction in there, but I might be able to pull out the relevant stuff? Not sure. I might take a look at some point but I'm not planning to prioritize it.

Anyway, that I know of it was not using any helper function supplied by Tumblr on the page at all; if I'm right about that you would have to do your own fetch(), I believe.

taracdia commented 1 year ago

Good to know, thank you!

cyle commented 1 year ago

Hello @taracdia ! Can you be more specific when you say "the page of the blog itself"? Can you give an example URL?

@marcustyphoon is correct that there is no available equivalent to the apifetch handler on legacy, pre-React-powered Tumblr pages. But we may be able to provide what you need as a hidden form field, depending on the page.

taracdia commented 1 year ago

Hi! When i say the page of the blog itself i mean I'd like to get the uuid of the blog from the html of the blog's "front page" at xxx.tumblr.com (I'm not sure if I'm answering what you're asking so sorry for any confusion!). One example of a page I'd like to work with is tyriantybalt.tumblr.com, but really I'd like to be able to work with any blog regardless of whether it is xxx.tumblr.com or tumblr.com/xxx or xxx.tumblr.com/page/23 etc. Thank you!

cyle commented 1 year ago

Ahh I see what you mean. Do you have a specific use case for this? We could force-inject the blog UUID on all of those blog pages, but at tumblr's scale, that would impact a very large number of page views per day.

An alternative could be for us to return the blog UUID in the v1 API top level "tumblelog" object, i.e. https://cyle.tumblr.com/api/read / https://cyle.tumblr.com/api/read/json -- would that suffice?

taracdia commented 1 year ago

That would be amazing thank you! And yes the use case I have is that I'm trying to make a Firefox Android extension modeled on XKit Rewritten for private use. I'm not planning on putting it in the extension store or sharing it around because I'm not very good at writing plain javascript so it's pretty hacky. The idea is that I'm piggybacking off of XKit Rewritten's quick reblog feature but making it even faster (because I reblog so often) by making the long click auto-reblog the post without having to click anything else. It works well on pages using window.tumblr but I'm trying to make it work on other blogs as well but since it relies on the window.tumblr object I'm running into issues. I'm mostly using this as an opportunity to familiarize myself with plain javascript and make something useful so please don't go to too much effort on my silly little project! But I do think that while the v1 stuff is still in use on some blogs it would be quite convenient to be able to get the uuid from the tumblelog object

marcustyphoon commented 1 year ago

I'd taken a look at your repository earlier; looks fun!

That I can tell, you don't currently have a way to actually perform the reblog from a non-react page without tumblr.apiFetch, right? If that's true you wouldn't just be looking for the blog UUID, I would assume. If you wind up needing to get an OAuth key and implement a way to access the v2 API without tumblr.apiFetch, then you'll have access to the necessary information anyway through that, and additions to the v1 API aren't beneficial!

taracdia commented 1 year ago

Thanks! I forgot my little project is public haha. Oh you're right! I was just kinda blindly following xkit's work because of my own unfamiliarity! That's what i get for not thinking ahead! Thank you for your time!

cyle commented 1 year ago

The uuid field is now available in the top level tumblelog object via /api/read (XML) and /api/read/json (JSON) on blogs!

Even if you don't need it anymore, it feels like a useful addition.

marcustyphoon commented 1 year ago

I tried out the v2 API as well! This is a piece of cake for fetching read-only public information, but I don't know offhand how to do an oauth authorization with write permissions in a web extension in order to be able to reblog.

const oauthConsumerKey = // from https://www.tumblr.com/oauth/apps

const test = async () => {
  const blogName = 'transienturl';

  const { meta, response } = await fetch(
    `https://api.tumblr.com/v2/blog/${blogName}/info?api_key=${oauthConsumerKey}`
  ).then(response => response.json());

  console.log(meta);
  console.log(response);
};

test();
taracdia commented 1 year ago

Oh cool thank you!