【问题标题】:Tumblr Posting Failed in iOS with error 404 in iOS native appTumblr 在 iOS 中发布失败,iOS 本机应用程序中出现错误 404
【发布时间】:2013-12-16 08:39:07
【问题描述】:

我的问题是我可以成功登录 tumblr 但是无法在 tumblr 上发帖。 下面是我的代码

 NSString *path = @"blog/myName.tumblr.com//post";            // set your Tumblr name here
    NSDictionary *parameters = @{@"type"  : @"text",
                                 @"title" : @"I'm On on Tumblr",
                                 @"body"  : @"Its going to be fun"};
    NSURLRequest *preparedRequest = [OAuth1Controller preparedRequestForPath:path
                                                                  parameters:parameters
                                                                  HTTPmethod:@"POST"
                                                                  oauthToken:_oauthToken
                                                                 oauthSecret:_oauthTokenSecret];

    // Send the request and when received show the response in the text view
    [NSURLConnection sendAsynchronousRequest:preparedRequest
                                       queue:NSOperationQueue.mainQueue
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                               dispatch_async(dispatch_get_main_queue(), ^{
                                   self.promptView.text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

                                   if (error) NSLog(@"Error in API request: %@", error.localizedDescription);
                               });
                           }];

下面是我设置 ConsumerKey、ConsumerSecrete 和回调 URL 的 oAuthController 实现文件

#define OAUTH_CALLBACK       @"tumblr_callback" //Sometimes this has to be the same as the registered app callback url
#define CONSUMER_KEY         @"MyKey"
#define CONSUMER_SECRET      @"MySecretKey"
#define AUTH_URL             @"http://www.tumblr.com/oauth/"
#define REQUEST_TOKEN_URL    @"request_token"
#define AUTHENTICATE_URL     @"authorize"
#define ACCESS_TOKEN_URL     @"access_token"
#define API_URL              @"http://api.tumblr.com/v2/"
#define OAUTH_SCOPE_PARAM    @"" 

下面是我收到的错误的屏幕截图

我哪里做错了。请对此提供任何帮助。

提前致谢。

【问题讨论】:

    标签: ios objective-c oauth tumblr


    【解决方案1】:

    代码方面,您可能想在这里寻找一些东西。

    您是否可以使用诸如“http://api.tumblr.com/v2/user/info”之类的 oauth 'GET' 请求?如果您可以收到成功的“GET”请求,那么您的访问令牌是有效的,您可以查看您是如何发送您的帖子参数的。

    确保将参数作为 HTTP 正文和签名参数传递。库可能提供了正确的参数顺序。

    NSString *postbody = @"body=myBodyText&type=text";
    
    [oRequest setHTTPBody:[postbody dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:TRUE]];
    

    ** 替代解决方案**

    实现TumblrUploadr

    总而言之,我使用 GTM-OAuth 登录并使用 TumblrUploadr 上传。对于那些寻求 Tumblr API 解决方案的人。

    更新: 一些关于 GTMOAuth 的信息,如果你想使用回调,你必须在 GTMOAuthAuthentication.m 中添加一个标志 > +(NSArray*)tokenAuthorizeKeys :在数组中添加 kOAuthCallbackKey 所以它将被考虑在内。否则,你没有回调。

    【讨论】:

    • 是的,我正在通过 get 请求获取访问令牌。这就是为什么我对我的 post 方法出了什么问题感到困惑。
    猜你喜欢
    • 2022-12-29
    • 1970-01-01
    • 2011-12-09
    • 2021-11-27
    • 1970-01-01
    • 2022-10-15
    • 2020-03-01
    • 2020-11-05
    • 2020-12-17
    相关资源
    最近更新 更多