-1

Reading the official documentation for Tumblr.js, it seems to require Node.js. I'd like to trigger a dialog box and let my app access the user blog. Can I make calls with vanilla JavaScript? I'd appreciate your help. I've been looking around the web and there is little information. Thanks.

HTML

<button onclick="loginTumblr();"> Connect Tumblr </button>

JS

function loginTumblr(){
//get user info + token

}
mikedidthis
  • 4,899
  • 3
  • 28
  • 43
Balloon Fight
  • 661
  • 8
  • 16
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Lawrence Cherone Oct 08 '17 at 00:51
  • 2
    I think what you're trying to ask is whether you can use the Tumblr API from the client side and not the server side – Sergio Alen Oct 08 '17 at 00:54
  • 1
    And by quickly browsing through the API I found this: In the Browser Due to CORS restrictions, you're going to have a really hard time using this library in the browser. Although GET endpoints on the Tumblr API support JSONP, this library is not intended for in-browser use. Sorry! – Sergio Alen Oct 08 '17 at 00:56
  • You can use the Tumblr API with vanilla javascript or a premade library (like Tumblr.js). Tumblr API documentation: https://www.tumblr.com/docs/en/api/v2 – mikedidthis Oct 09 '17 at 08:56

2 Answers2

1

The answer is "probably," but it certainly won't be secure. Accessing an API from from the client side is risky because you'll have to expose your app's private credentials to the end user.

What you said regarding needing node is not necessarily correct; you could use any server side scripting (e.g., PHP) to safety call the api.

Nick
  • 16,066
  • 3
  • 16
  • 32
0

In all cases, make sure you are not exposing your keys or endpoints where other people could use your keys to access your personal account.

If you learn OAuth and CORS, you might be able to write an axios or fetch client. Node's "request" module is not easy to reverse engineer into client-side JS code. The browser versions I've seen don't support the OAuth addon it uses.

If you deploy to now.sh or a VPS, or write an Electron desktop client, you could use the node, golang, or python clients in the backend to proxy tumblr requests.

If you deploy to netlify, you could use the node or golang netlify functions to proxy tumblr requests.

If you deploy to any VPS environment or use serverless/lambda/cloudfunctions, you could proxy tumblr requests in most of the available cloud libraries.

I suspect you could compile the golang or c client to webassembly and expose their functions to JavaScript, but I don't recommend trying this.

Michola Ultra
  • 145
  • 1
  • 13