Re: Help, programmatically created Like/Unlike <a> links aren't registering Likes

139 views
Skip to first unread message
Message has been deleted

John Drefahl

unread,
Mar 26, 2015, 6:24:31 PM3/26/15
to tumbl...@googlegroups.com
Updated:  I have tried the following URL patterns as directed by the Tumblr API, and i am still getting 401 Errors.

api.tumblr.com/v2/user/like?reblog_key=mThpzZ4l&id=114337695805

api.tumblr.com/v2/user/like?reblog_key=mThpzZ4l?id=114337695805

Any help would be greatly appreciated..


On Tuesday, March 24, 2015 at 10:44:00 AM UTC-7, John Drefahl wrote:
Hello group!

Curious if someone could help me out here as I am trying to create like/unlike functionality for each post item we have coming into a custom theme that is basically a tumblr aggregator.

So we are pulling all our assets out of Tumblr via the API.  That's working fine, no problem there.  We have successfully created Reblog links.  However, the following <a>nchor link patterns are not working for our "Like" / "Unlike" functionality.  I have tried both.

#1
First try was this: http://www.tumblr.com/<command>/<oauthId>?id=<postId>

This is what we get: Access Denied

#2
I have also tried this:
<a href="#like" title="Like" data-key="'reblog_key" data-id="post_id">Like</a>
The behavior we get: The page refreshes, but a "Like" isn't registered within Tumblr.

What am I missing?  Is there some Javascript I need to put in that's hidden within a Tumblr script?  From the API docs, the first attempt seemed the most straight forward, but I keep getting "Access Denied" no matter what values I test in the link.  We are aware that Tumblr would like us to use their theme tags for this, but its not practical for what we are doing.

Thanks ahead of time to anyone out there who helps me out!

Thanks
John





John Bunting

unread,
Mar 26, 2015, 6:26:36 PM3/26/15
to tumbl...@googlegroups.com
This is the incorrect way to use the API to actually like something, please review: https://www.tumblr.com/docs/en/api/v2

There are api clients to help you make your requests if you need.

--
You received this message because you are subscribed to the Google Groups "Tumblr API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tumblr-api+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
John Bunting

Simplicity is prerequisite for reliability
    --Edsger W. Dijkstra

John Drefahl

unread,
Mar 26, 2015, 6:47:51 PM3/26/15
to tumbl...@googlegroups.com
I know, I have been there.. So perhaps you can help on on that end..  I have install require.js and tumblr.js.

Would I just bind an onClick event to my "Like" button, and throw in the output below which was generated by the API explorer?
// Authenticate via OAuth var tumblr = require('tumblr.js'); var client = tumblr.createClient({ consumer_key: 'MVfDczvR2DLvYQNylA7vknZ5MEZNttkWSYsA8ws9vhShs9sbxA', consumer_secret: 'XXXXXXXXXXXXXXXXXXXXXXXX', token: 'ekE6WUS7hFGkuwVXyQxSs0bTFQ2y1647xzHoUuJs3c6z7wmOjh', token_secret: 'XXXXXXXXXXXXXXXXXXXXXXXX' });

// Make the request client.like(undefined, '', function (err, data) { // ... });


I really appreciate any help on this.. The API docs are just very unclear. With Reblog all we had to do was build a URL query, It's confusing that you have to do something completely different for Likes.\\

john

John Drefahl

unread,
Mar 26, 2015, 6:52:02 PM3/26/15
to tumbl...@googlegroups.com
My bad it should actually be this.. but tell me if I am going in the right direction here with deploying this code..

$(document).on("click", "a.tumblrNotLiked", function() {

// Authenticate via OAuth
var tumblr = require('path to/tumblr.js');
var client = tumblr.createClient({ consumer_key:
consumer_key: 'MVfDczvR2DLvYQNylA7vknZ5MEZNttkWSYsA8ws9vhShs9sbxA', consumer_secret:
consumer_secret: 'XXXXXXXXXX', token:
token: 'ekE6WUS7hFGkuwVXyQxSs0bTFQ2y1647xzHoUuJs3c6z7wmOjh', token_secret:
token_secret: 'XXXXXXXXXXXX'
});
// Make the request
client.like(114504470102, '2Mz5eaKo', function (err, data) {
// ...
});

$(this).switchClass("tumblrNotLiked","tumblrLiked");
});

Thanks any help much appreciated..

John Bunting

unread,
Mar 26, 2015, 6:52:18 PM3/26/15
to tumbl...@googlegroups.com

It's a post request so it needs to go in the body of the request.

John Drefahl

unread,
Mar 26, 2015, 7:05:24 PM3/26/15
to tumbl...@googlegroups.com
So, I wasn't even close.. So these are all just straight ajax requests?

xmlhttp.open("POST","api.tumblr.com/v2/user/like",true);
xmlhttp.send("reblog_key=2Mz5eaKo_id=114504470102");

Am I getting warmer?

john

John Drefahl

unread,
Mar 26, 2015, 7:12:32 PM3/26/15
to tumbl...@googlegroups.com
I guess the bigger answer to my question is now.. If it is just a simple AJAX post, then what if the user isn't logged in?  How are they kicked to a login?  Or do I have to detect that they aren't logged in.. and then facilitate an entire OATH authentication?!?!  This is getting to be a bit annoying, being all that anyone wants to do is LIKE A POST!.

With the reblog link, it was very simple.. write out link, and if they are logged in, great it reblogs, if not, they are sent through the Tumblr authentication.  Why do they treat the Like so differently when they both require the same attributes.. 

Sort me out, ill send you some BTC or something.
John

John Drefahl

unread,
Mar 26, 2015, 7:34:56 PM3/26/15
to tumbl...@googlegroups.com
Argh, I am starting to see the light here.. So, basically there is no way to do this outside of using the tumblr.js library..  That being said, I need to handle the oath and send that with the request in the header or something.  What I am unclear about is.. how do I hand off authentication to Tumblr if they aren't logged in?.  Not sure how to do this yet.. but I suppose I will figure it out, unless someone wants to just drop the knowledge and hear 100000 million people go, 'Damn, thats dumb' all at once.. and then thank you for just sorting it out.

john

John Drefahl

unread,
Mar 26, 2015, 7:41:35 PM3/26/15
to tumbl...@googlegroups.com
Oh well, no tumblr.js for me, because I can't run node.js on this project.. back to my initial question.. how do you like a post without the fancy pants stuff.

john

John Drefahl

unread,
Apr 7, 2015, 1:59:17 PM4/7/15
to tumbl...@googlegroups.com
Found an answer!

So let me break it down for you all..  I am just going to run down all the issues and caveats that were discovered while I was hacking away at the Tumblr API.  In most cases you will not find any of these answers on the inter webs.  If you do, they most likely will just be my answers to my own questions that I posted to the Forums.
  1. A Tumblr Application is defined by any page template either hosted by Tumblr or not that will be using the Tumblr API.  Applications must be registered with Tumblr at:  https://www.tumblr.com/oauth/apps

  2. All Tumblr Applications upon creation are given a set of keys for accessing the Tumblr API.
    1. OAuth Consumer Key aka API Key
    2. Secret Key

  3. The Tumblr API is divided mainly into two different types of methods.  The third being “Tagged” which is for pulling tagged posts from the Blog or the User.
    1. “Blog Methods” which only require the submission of the Consumer Key.
    2. “User Methods” which require a full OAuth signed request which meets the OAuth 1.0a Protocol.
      1. The “User Likes” returns a maximum of 50 records at a time.  This is not documented in the Tumblr API docs.

  4. Currently the Tumblr API documentation directs developers to use one of the many open source API clients.  However, all these clients seem to be Server Side applications.  For providers, such as Tumblr, which support only OAuth1 or OAuth2 with Explicit Grant, the authentication flow needs to be signed with a secret key that may not be exposed in the browser. HelloJS gets round this problem by the use of an intermediary webservice defined by oauth_proxy. This service looks up the secret from a database and performs the handshake required to provision an access_token. In the case of OAuth1, the webservice also signs subsequent API requests.

  5. HelloJShttp://adodson.com/hello.js/ is the only client-side Oauth library that was available and free.  There are many services out there that charge on a per-api hit basis to serve as a proxy.
    1. The HelloJS OAuth Proxy is available at: https://auth-server.herokuapp.com/
    2. Login to the OAuth Proxy is done using one of the following social account credentials: Google, Windows Live, Facebook, or Yahoo.
    3. OAuth Proxy serves as a secure “man in the middle” allowing for the “Secret Key” to be securely stored while still allowing for Client-Side OAuth authentication.

  6. HelloJS features a special Tumblr Modulehttp://adodson.com/hello.js/demos/tumblr.html

  7. HelloJS utilizes the new Javascript Promises asynchronous functions specification - https://www.promisejs.org/

  8. Javascript Promises have some unique rules when it comes to passing objects received from an asynchronous AJAX call.
    1. With everything is done in the callback.
    2. What jQuery calls a promise is in fact totally different to what everyone else calls a promise.

Hope this helps for future Tumblr integrations.

John

Reply all
Reply to author
Forward
0 new messages