Skip to content

Instantly share code, notes, and snippets.

@ydn
Created August 20, 2015 00:51
Show Gist options
  • Save ydn/6119c0bd818dd9a51ddb to your computer and use it in GitHub Desktop.
Save ydn/6119c0bd818dd9a51ddb to your computer and use it in GitHub Desktop.

iOS

  • Register for an API key
  • Explore the API
    • You can view and interact with some of the available data in the API at https://api.tumblr.com/console
      • Check out the Objective-C section to get a quick start on some code to connect to the API
    • Documentation for the REST API is available at https://api.tumblr.com/
  • General Info
    • Tumblr uses OAuth 1.0a
      • Might want to hardcode particular tokens for testing instead of wrangling the OAuth dance. Can retrieve tokens by logging into the API Console
    • Authentication is per-user, and you will have full access to all blogs the user has access to.
    • REST API responses have top-level fields of “meta” and “response”. The SDK reads from the “response” into anid, and places into identical keys.
    • Any input parameters shown in the REST API docs are also accepted in any “parameters” NSDIctionary
    • Different post types have different content fields. All content is HTML.
      • Text - "body"
      • Photo/Video/Audio - "caption"
      • Refer to the https://api.tumblr.com/ for specifics and other available fields.
  • Examples
    • Setup the OAuth tokens

      [TMAPIClient sharedInstance].OAuthConsumerKey = @"...";
      [TMAPIClient sharedInstance].OAuthConsumerSecret = @"...";
      [TMAPIClient sharedInstance].OAuthToken = @"...";
      [TMAPIClient sharedInstance].OAuthTokenSecret = @"...";
    • Read the dashboard

      [[TMAPIClientsharedInstance] dashboard:nil
                                    callback:^ (id result, NSError *error) {
                                       if (error) {
                                           NSLog(@"Something borked: %@", error);
                                       }
                                       NSLog(@"First post from: %@", result[@"posts"][0][@"blog_name"]);
                                }];
    • Look-up a post

      [[TMAPIClient sharedInstance] posts:@"david.tumblr.com"
                                     type:nil
                               parameters:@{ @"id" : @120053947615 }
                                 callback:^ (id result, NSError *error) {
                                    NSLog(@"Caption: %@", result[@"posts"][0][@"caption"]);
                             }];
    • Reblog a post

      Requires a “reblog_key” which is returned along with any post object

      [[TMAPIClient sharedInstance] reblogPost:@"my-blog.tumblr.com"
                                    parameters:@{ @"id" : @120053947615, @"reblog_key" : @"htETXlZA", @"comment": @“Added text" }
                                      callback:^ (id result, NSError *error) {
                                         NSLog(@"New post ID: %@", result[@"id"]);
                                  }];
    • Create a post

      [[TMAPIClient sharedInstance] post:@"my-blog.tumblr.com"
                                    type:@"text"
                              parameters:@{ @"title": @"My title", @"body" : @"My body" }
                                callback:^ (id result, NSError *error) {
                                   NSLog(@"New post ID: %@", result[@"id"]);
                            }];

Android

  • Register for an API key
  • Add the Tumblr SDK
    • https://github.com/tumblr/jumblr
    • Install using Gradle
      • In build.grade:

        dependencies {
            compile 'com.tumblr:jumblr:0.0.11'
        }
      • May also need:

        android {
            packagingOptions {
                exclude 'META-INF/LICENSE.txt'
                exclude 'META-INF/NOTICE.txt’
            }
        }
  • Explore the API
  • General Info
    • Tumblr uses OAuth 1.0a
      • Might want to hardcode particular tokens for testing instead of wrangling the OAuth dance. Can retrieve tokens by logging into the API Console
    • Authentication is per-user, and you will have full access to all blogs the user has access to.
    • REST API responses have top-level fields of “meta” and “response”. The SDK wraps these into objects, as found in com.tumblr.jumblr.types.
    • Any input parameters shown in the REST API docs are also accepted in any Map<String, ?> options, found as an overload to most calls.
    • Different post types have different content fields. All content is HTML.
      • Text - “body”
      • Photo/Video/Audio - “caption”
      • Refer to the https://api.tumblr.com/ for specifics and other available fields.
  • Examples
    • Setup the OAuth tokens

      JumblrClient client = new JumblrClient("...", "...");
      client.setToken("...", "...");
    • Read the dashboard

      List<Post> posts = client.userDashboard();
      for (Post post : posts) {
         if (post instanceof PhotoPost) {
             System.out.println(((PhotoPost) post).getCaption());
         }
      }
    • Look-up a post

      Post post = client.blogPost("david.tublr.com", 120053947615L);
      System.out.println(((PhotoPost) post).getPhotos().get(0).getOriginalSize().getUrl());
    • Reblog a post

      Post post = client.blogPost("david.tumblr.com", 120053947615L).reblog(“my-blog.tumblr.com");
      System.out.println(post.getId());
    • Create a post

      QuotePost post = client.newPost("my-blog.tumblr.com", QuotePost.class);
      post.setText("hello world");
      post.save();
      System.out.println(post.getPostUrl());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment