如何在 iOS 中使用 TMTumblrSDK post 将图片上传到 Tumblr

How to post a pic to Tumblr using TMTumblrSDK in iOS

我正在尝试将 Tumblr 集成到我的应用程序中,以便将图片 post 简单地 posting 到 tumblr 中。

我在遵循tumblr 的身份验证过程时感到困惑。

我注册了应用程序。

我有消费者密钥和消费者密钥。

我已使用 OAuthConsumer 请求令牌和令牌密钥。

但是我无法执行下一步,即 post拍照。

这是我用来验证的代码:

     [[TMAPIClient sharedInstance]authenticate:@"myappURLScheme" callback:^(NSError *err) {

        NSLog(@"authentication failed %@",err);
    }];

这会将我带到 safari tumblr 页面,执行允许/不允许 process.After 我点击允许,它会把我带到 tumblr 应用程序。但图片未 posted.

这是我尝试 post 图片:

[[TMAPIClient sharedInstance] photo:@"Sample Upload"
                      filePathArray:@[[_imagesPath stringByAppendingPathComponent:
                                       @"tm.png" ]]
                   contentTypeArray:@[@"image/png"]
                      fileNameArray:@[@"tm.png"]
                         parameters:@{@"caption" : @"Caption"}
                           callback:^(id response, NSError *error) {
                               if (error)
                                   NSLog(@"Error posting to Tumblr %@",error);
                               else
                                   NSLog(@"Posted to Tumblr %@",error);
                           }];

这里出现错误:

  Error posting to Tumblr Error Domain=Request failed Code=404 "(null)"

响应参数也为空

我相信验证成功了,我也可以从Tumblr 获取用户信息。但我不确定为什么照片没有 posted .

示例上传是您的博客吗?我不得不承认 Tumblr 的命名约定真的很糟糕,但是如果你检查代码,你会发现你需要在那里传递博客名称。

- (void)photo:(NSString *)blogName filePathArray:(NSArray *)filePathArrayOrNil contentTypeArray:(NSArray *)contentTypeArrayOrNil
fileNameArray:(NSArray *)fileNameArrayOrNil parameters:(NSDictionary *)parameters callback:(TMAPICallback)callback;

否则请确保在发送请求之前设置 OAuthConsumerKeyOAuthConsumerSecretOAuthTokenOAuthTokenSecret

你的代码在其他方面看起来不错,对我来说差不多。