iosauthenticationoauthtumblr

Tumblr reblog (TMTumblrSDK) return 401 error


I use TMTumblrSDK :

NSDictionary *params = @{
                     @"id" : 999999999999,
                     @"reblog_key": @"XXXXXX",
                     @"comment" : @"test comment",
                     };  

[[TMAPIClient sharedInstance] reblogPost:@"test.tumblr.com"
                          parameters:params
                            callback:^(id response, NSError *error) { 

...

response:
{
   meta = {
   msg = "Not Authorized";
   status = 401;
};
   response = (
);
}

OAuthConsumerKey, OAuthConsumerSecret, OAuthToken, OAuthTokenSecret is set correctly. Methods "user/follow" "user/like" and "user/unlike" work correctly.

A similar question about android-version: Getting 401 (Not Authorized), when calling Tumblr post reblog api also unanswered.


Solution

  • I solved my problem. In the "reblogPost" value necessary to transmit blog url logged in user, not the blog url, reblogged we want to do. For example, if we want to do reblogged post of "test" user, we must not pass "test.tumblr.com". We must pass "loggedUser.tumblr.com".

    It can be obtained using the method userInfo. For example:

    NSString* baseHostname;
    [[TMAPIClient sharedInstance] userInfo: ^(id result, NSError* error) {
    
             NSString * baseHostname = [result[@"user"][@"blogs"][0][@"url"] // first blog     
                                       stringByReplacingOccurrencesOfString:@"http:" withString:@""];
             baseHostname = [baseHostname stringByReplacingOccurrencesOfString:@"/" withString:@""];
    
         [[TMAPIClient sharedInstance] reblogPost: baseHostname  // @"loggedUser.tumblr.com"
                           parameters: params
                             callback: ^(id response, NSError * error) {
            ...
         }];
    
    }];