New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support for the new Tumblr API (OAuth-based) #2

Closed
bucciarati opened this Issue Jul 1, 2013 · 22 comments

Comments

Projects
None yet
3 participants
@bucciarati
Copy link
Contributor

bucciarati commented Jul 1, 2013

Tumblr's API v2 has superseded the old one (to the best of my understanding the old API is not working anymore, its docs are only there for e-rcheologists and sections about authentication and post submission have been completely removed).

It would be cool to have WWW::Tumblr support the new version (I can help with code and testing if needed).

Thanks!

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 16, 2013

Hi!
Have you solved this issue?
I was able to force Tumblr v2 API working with Net::OAuth module, I'm building the 'TumblrV2' library now to have all things combined. If you are ready to help – you are welcome, first version will be available today :)

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 16, 2013

Great! I am ready to help. Wanna merge it on this repo?

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 17, 2013

I finished the base part of oAuth Tumblr v2 API, I've tested it only with blog posting, so it miss other methods for now, but it's easy to add them. Since I will not have much time to work on other methods implementation and testing till weekends, you can help here :).
Any notes and advises are appreciated :)

Sources: https://github.com/netangel/www-tumblr/blob/master/lib/WWW/TumblrV2.pm

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 17, 2013

WWW::Tumblr is good module's name, I think we could do next steps:

  1. Finish and test new api implementation (TumblrV2)
  2. Replace old Tumblr.pm with new one
@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 17, 2013

Sounds good. I'll work on this tonight.

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 17, 2013

Sorry for lack of comments, I was tight in time :).
I'm going to add some comments and documentation soon.

@bucciarati

This comment has been minimized.

Copy link
Contributor

bucciarati commented Jul 18, 2013

FWIW, I quickly tested it and it works for me:

% perl -w -Mstrict -Iwww-tumblr/lib -MWWW::TumblrV2 -E '
my $t = WWW::TumblrV2->new(
  blog =>         $ENV{blog},
  consumer_key => $ENV{consumer_key},
  secret_key =>   $ENV{secret_key},
  token =>        $ENV{token},
  token_secret => $ENV{token_secret},
);
say $t->post( type => "text", title => "eppur", body => "si muove" );
'
{"meta":{"status":201,"msg":"Created"},"response":{"id":55738049348}}

Awesome!

@bucciarati

This comment has been minimized.

Copy link
Contributor

bucciarati commented Jul 18, 2013

FYI I'm waiting on TumblrV2 to be released before I can release this: bucciarati/poe-component-irc-plugin-tumblr@17fed1d

If one of you guys is working on V2 I'll just wait, otherwise just tell me and I can work on docs for it one of these evenings; I'd like to have it ready before the AmsterdamX.pm meeting on Monday 22 so I can spam it to people ;)

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 18, 2013

I'm planing to finish other methods in next 2 days. Also I want to create 2 examples, cause getting the auth url and token is quite tricky because of Net::OAuth features.
Please note, I suppose the WWW::Tumblr should be more suitable name for module (TumblrV2 is the temporary development name :))

@bucciarati

This comment has been minimized.

Copy link
Contributor

bucciarati commented Jul 18, 2013

Will the example in my comment help? You can use that or tweak it: #2 (comment)

Those arguments are all that is needed in order to submit posts. You may want to add some examples in the docs for other types of operations (following, reblogging, editing, deleting, ...).

Also you might want to link http://www.tumblr.com/docs/en/api/v2 and/or http://www.tumblr.com/oauth/apps which detail the steps needed to register an application and obtain OAuth tokens.

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 20, 2013

@netangel: I faced pretty much the same problem with your TumblrV2 than with the stuff I didn't end up pushing: The access token and access token secret retrieval. I believe Net::OAuth has a problem on how Tumblr is handling that, for whatever reason. So my question is, how did you retrieve the token and token secret? Did you use the authorization_url method from Net::OAuth, etc? Because it doesn't work for me.

This is what I'm doing:

my $t = WWW::Tumblr->new(
    consumer_key => 'wakawaka',
    secret_key => 'wakawaka2'
);

print $t->authorization_url, "\n";
chomp( my $res = <STDIN> );

my ( $oauth_token, $oauth_verifier ) = $res =~ /oauth_token=(.+?)&oauth_verifier=(.+?)/;

my ( $token, $token_secret ) = $t->get_token( $oauth_token, $oauth_verifier );

print "I got token: $token \n";
print "I got token_secret: $token_secret \n";

print Dumper $t->post( type => "text", title => "eppur", body => "si muove" );

This is using TumblrV2. After the authorization_url gets printed, I go to it, allow access to it and Tumblr sends me to fake.com with query string parameters of oauth_token and oauth_verifier. Then I take those, paste, capture and pass them to get_token(). Invariably, I get a 403 from Net::OAuth with something like:

oauth_signature [EtqUniq3lWN1RXmrIo1eRGv8YBA=] does not match expected value [b3d4MZixYW+XW3F0xopuXs5x3SM=]
at ../lib/WWW/Tumblr.pm line 73.

I briefly discussed with @bucciarati and he was getting those tokens from somewhere else. What's your case?

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 20, 2013

I've updated Tumblr.pm, a little. And added two examples. The Net::OAuth::Client is using session to store some temporary values, (the token => token_secret key-value, to be exact), this key-value first appears in Net::OAuth::Client::authorize_url, and then is used in Net::OAuth::Client::get_access_token but we cannot get if directly from authorize_url, so it needs to store session.
Please, check https://github.com/netangel/www-tumblr/blob/master/examples/tumblr.cgi, it will not compile, but you can get the idea. I'll make it fully working later.

When Tumblr.pm is used in 'live' environments like Dancer or Mojolicious, there is no need in store/restore session steps. Check the https://github.com/netangel/www-tumblr/blob/master/examples/mojo_tumblr, it's a small working example.

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 21, 2013

Please checkout my origin/v2 branch. I have designed the base API to comply properly with Tumblr's. That is, using OAuth, API key or "none" authentication. There's three different buckets: User, Blog and, in the future, Tagged, as the documentation states. This is better as a WWW::Tumblr object can be used for different blogs or none at all but for the user.

use WWW::Tumblr;

my $t = WWW::Tumblr->new({
    consumer_key => 'foo',
    ... # the other 3
});

my $blog = $t->blog('myblog.tumblr.com'); #this will return a WWW::Tumblr::Blog object
if ( ! $blog->post({ type => 'text', title => 'Perl', body => 'rules!' }) ) {
    die "Failed! " . $blog->error->code;
} else { print "yeha!\n"; }

In this case, you can instantiate WWW::Tumblr::Blog directly with the same constructor arguments as WWW::Tumblr or just do it for WWW::Tumblr::User;

my $user = WWW::Tumblr::User>new({ the four tokens });
print Dumper $user->info; # etc....

I have implemented a bunch of OAuth authentication methods using @netangel's initial code. I will complete these soon and follow up on the API key and none ones that should be even simpler.

As said, this is all done on the v2 branch.

Cheers,
dm.

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 21, 2013

Looks great.
What methods are you implementing now? We can divide task to complete all Tumblr API methods.
BTW, I cannot see the authorization_url and token receive methods in your version. How can I move your v2 branch to my master branch? (I gonna read the Git Book now) :)

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 22, 2013

The authorization_url and get_token methods are still there but as unimplemented. They are under END. I was planning on bringing them back to life as soon as I could have most of the methods and base API ready. If you wanna pick that up, bring them to the WWW::Tumblr package, or even better a more suitable package and make it work with the Web app examples, that'd be sweet.

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 22, 2013

We can put the authorization_url and get_token methods in WWW::Tumblr or WWW::Tumblr::Tools, what do you think? Since there are no other methods connected with authorization/token we can implement them in the base class. Also I'll think how to do with sessions in better way.

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 22, 2013

I would like to move all oauth methods into WWW::Tumblr::Authentication::OAuth. Same for APIKey and None. Tools could be there or even on WWW::Tumblr::Authentication::OAuth::Tools.

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 29, 2013

@damog

This comment has been minimized.

Copy link
Owner

damog commented Jul 30, 2013

Ah, that looks great. I'm currently working on adding test cases for all the methods so hopefully this can be released finally this week. If you can provide a pull request for this on the current master branch that'd be awesome. cheers.

@netangel

This comment has been minimized.

Copy link
Collaborator

netangel commented Jul 30, 2013

Pull request created, please take a look. If you need any help with tests, please, let me know.
I'm planning to test the image upload procedure, cause I suppose it could be tricky.

@damog

This comment has been minimized.

Copy link
Owner

damog commented Aug 20, 2013

I have finally completed the basic full implementation of the API and uploaded it to PAUSE as WWW::Tumblr version 5.00_01. I plan to do some other minor fixes before uploading final 5.00.

@netangel: It'd be great if you could draft some documentation for the authorization work for oauth tools and etc.

Thanks everybody for the help!

@damog damog closed this Aug 20, 2013

@damog

This comment has been minimized.

Copy link
Owner

damog commented Aug 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment