tumblr

PostToTumblr v3.18 – Fixed Tumblr oauth change

head

 

Just a quick update to say I have now fixed the authentication issue my PostToTumblr that quite a few people contacted me about.

What was going on was that Tumblr appear to have changed the format of the data they return from a token request which was causing a library that PostToTumblr relies on to fail.

Before PostToTumblr can post content on a users behalf it first must get an “access token”. This token is given to PostToTumblr as part of the authentication flow.

When PostToTumblr first starts up it checks to see if it still has a valid token (they can expire over time and other various reasons). If it doesnt it must go through the authentication flow. Firstly it redirects the user to the grant permission dialog:

screenshot_02

When the user clicks allow Tumblr then returns an “oauth token” and an “oauth verifier” to PostToTumblr, which it can then use to get an “access token” which is used to do the posting.

The problem that this update fixed was that the “oauth verifier” that was returned from Tumblr changed:

screenshot_03

You see at the end of the query string there is now a “#_=_” well this was causing havoc with the URL parameter parsing code in the Google oauth library I was using.

My solution is quick and dirty, just strip out the “#_=_” from the url while parsing:

// MIKE HACK!!	  
if(param.indexOf('oauth_verifier=')!=-1) 
{
	param = param.replace('oauth_verifier=','');
	param = param.replace('#_=_','');		  
	decoded['oauth_verifier'] = ChromeExOAuth.fromRfc3986(param);
}
else
{	  	  
	var keyval = param.split("=");
	if (keyval.length == 2) {
		var key = ChromeExOAuth.fromRfc3986(keyval[0]);
		var val = ChromeExOAuth.fromRfc3986(keyval[1]);
		decoded[key] = val;
	}
}

Well I hope this helps anyone else that may encounter this issue too!

PostToTumblr v3.12 Update

head

I have finally found some time to do a long overdue update to my popular Chrome extension PostToTumblr built using Haxe. 30,000 people currently have the extension installed and they post about 10,000 images, links, quotes per day so I thought it was about time to give it some love.

The list of improvements are:
+ One-Click posting now available in the options
+ Tall images now no longer appear off the screen
+ Notifications now used instead of popups
+ Improved error detection
+ Improved authorization process

The main feature in the update is the one-click posting. This much-requested feature was available in the original PostToTumblr but for various reasons never made it into the latest reincarnation.

screenshot_01

Once enabled in the options it enables the user to bypass the post preformatting window that usually pops up and instead posts with some default settings. If you have more than one blog the post menu gives you the option for which blog you would like the post to go to:

screenshot_05

The normal popup “posting..” window has been replaced with HTML5 notifications.

screenshot_02

This should make posting a smoother, less intrusive process.

If you haven’t got the extension already you can grab it on the Chrome Store else Chrome should auto-update the extension for you very soon!

All New Post To Tumblr Chrome Extension created with Haxe & Robotlegs

I have been working off and on for a while on an update to my popular Chrome Extension ‘Post To Tumblr’ and seeing as Tumblr have just changed thier API I thought it was time to accelerate its development and release it, finally.

First some screenshots to give you an idea of what it does:

You can right-click any thing on a page and “Post To Tumblr”.

A new tab opens where you can format it how you like.

You can change the post type very easily.

When done you just “Create Post”

This version is written totally from scratch using Haxe’s Javascript target. Although not strictly necessary for something as simple as this I thought it was a good opportunity to experiment around with Haxe’s JS capabilities. I must admit I was pleasantly surprised at how well it worked.

Most stuff just worked. There are also plenty of externs out there for the popular Javascript libraries on lib.haxe.org such as the “chrome-extension” library.

Having type-safe Javacript is great for for so many reasons that im not going to get into here. I must admit however there were times when I was lazy and didn’t want fancy creating a type-safe extern class for a library. Fortunately however Haxe has a mechanism for the lazy coder in the form of “untyped”.

An example of this is the way in which you access the “localStorage” object in chrome extensions. localStorage is basically a global object that you can set keys and values in and will persist for the life of your extension. To access it you use: “localStorage[myKey]” to return a value. If you tried to do that in Haxe it would throw an error because Haxe has no concept of global variables (quite rightly).

So to access the localStorage you can use untyped to quickly get access to a global variable, I then decided to wrap this little hack in a Model class to make it a little neater:

  1. package models;
  2. import js.Lib;
  3.  
  4. /**
  5.  * ...
  6.  * @author MikeC
  7.  */
  8.  
  9. class ChromeLocalStorageModel extends BaseModel
  10. {
  11.  
  12. public function get(key:String) : Dynamic
  13. {
  14. var val = untyped localStorage[key];
  15. trace('Getting from localStorage: '+key+" :: "+val);
  16. return val;
  17. }
  18.  
  19. public function set(key:String, val:Dynamic) : Void
  20. {
  21. trace('Saving in localStorage: '+key+" :: "+val);
  22. untyped localStorage[key] = val;
  23. }
  24.  
  25. }

This lets you just just mix and match the type-safe stuff when you need to and just do a little “hack” when you need to ;)

The above example also shows off another cool feature im using in Post To Tumblr, which is RobotLegs. Thanks to the fact that the RobotHaxe library is written in pure Haxe (has no platform specific bits) that means I am able to use it on a Javascript project.

The only problem is the issue with Views and Mediation. Because unlike Flash events don’t bubble up to a central source there is no way to do automatic mediation in the JS target. Instead what you do is implement “IViewContainer” on your context view, then whenever a child is added or removed you call viewAdded() or viewRemoved() that way the MediatorMap can try to make a mediator for that view.

Im not sure if the way I have used RobotLegs is the correct or best way, it was more of an experiment as I went along. The way I have done it is to wrap many of the main HTML elements in my own view classes. So for example I have a “DivView” that represents a “div” and extends BaseView:

  1. class DivView extends BaseView
  2. {
  3.  
  4. public function new(elementId:String=null)
  5. {
  6. super(Lib.document.createElement('div'));
  7. if (elementId != null) element.id = elementId;
  8. }
  9.  
  10. }

BaseView implements the IViewContainer interface:

  1. class BaseView implements IViewContainer
  2. {
  3. public var viewAdded:Dynamic -> Void;
  4. public var viewRemoved:Dynamic -> Void;
  5.  
  6. public var element : HtmlDom;
  7. public var parent : BaseView;
  8. public var children : Array;
  9.  
  10. ....
  11.  
  12. public function new(element:HtmlDom)
  13. {
  14. this.element = element;
  15. this.children = [];
  16. isLayoutInvalid = true;
  17. }
  18.  
  19. ...
  20.  
  21. public function add(child:BaseView) : BaseView
  22. {
  23. children.push(child);
  24. child.parent = this;
  25. child.viewAdded = viewAdded;
  26. child.viewRemoved = viewRemoved;
  27. if(viewAdded!=null) child.addChildren();
  28. element.appendChild(child.element);
  29. if (viewAdded != null) viewAdded(child);
  30. return child;
  31. }
  32.  
  33. public function remove(child:BaseView) : Void
  34. {
  35. if (viewRemoved != null) child.removeChildren();
  36. children.remove(child);
  37. child.parent = null;
  38. child.viewAdded = null;
  39. child.viewRemoved = null;
  40. element.removeChild(child.element);
  41. if (viewRemoved != null) viewRemoved(child);
  42. }
  43.  
  44. ...
  45.  
  46. }

Then say I want to construct the following html:

<div id="container">
	<div id="inner">Hello World!</div>
</div>

I would do something like this:

  1. class MainPopupContainer extends DivView
  2. {
  3. private var inner : DivView;
  4.  
  5. public function new()
  6. {
  7. super("container");
  8.  
  9. inner = new DivView("inner");
  10. inner.element.innerHTML = "Hello World!";
  11. add(inner);
  12. }
  13. }

Then perhaps I want to turn the “Hello World!” red when clicked I would do something like this:

  1. class MainPopupContainer extends DivView
  2. {
  3. private var inner : DivView;
  4.  
  5. public function new()
  6. {
  7. super("container");
  8.  
  9. inner = new DivView("inner");
  10. inner.element.innerHTML = "Hello World!";
  11. add(inner);
  12.  
  13. new JQuery(inner.element).click(onInnerClicked);
  14. }
  15.  
  16. private function onInnerClicked()
  17. {
  18. inner.element.style.color = "#FF0000";
  19. }
  20. }

What this means is you have a RobotLegs-familiar looking View with a Mediator behind it (thanks to the mediation happening when you call add()) which is nice. What it does mean however is I have quite abit of boiler plate wrapping the HTML nodes, which definitely slowed down my development.

Another thing im not sure about is my mixing of in-line styles and stylesheets. Sometimes I would use the styles in my css and other times I would just set them on the element directly. To be honest, because I was using classes and inheritance and all that good stuff I usually found it easier and more expedient to set the styles inline in my View class rather than go digging through several hundred lines of css to find the selector I was looking for

For example I may have a “HeaderOptionButton” that defines some inline styles then whenever I wanted a button that looked and acted like a header button I would just make and add a HeaderOptionButton. I know im probably going to get flamed to hell and back for that!

As I said, im not sure if im doing it the “right” or “best” way, its just the way that seemed to work at the time ;)

Well that’s a quick overview of where im at. Once I have cleaned the project up a little and added some missing features ill be sticking the source up on GitHub for anyone interested.

1 2 3  Scroll to top