【问题标题】:Can't post to Twitter from my iPhone app无法从我的 iPhone 应用程序发布到 Twitter
【发布时间】:2011-07-03 19:58:28
【问题描述】:

我正在使用这一小段代码在 Twitter 上发帖,用真实凭据代替“mytwitterloginname”和“mytwitterpassword”占位符:

void _StartTwitter()
{

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
                                    [NSURL URLWithString:@"http://mytwitterloginname:mytwitterpassword@twitter.com/statuses/update.xml"] 
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];

    // The text to post
    NSString *msg = @"testing";

    // Set the HTTP request method
    [request setHTTPMethod:@"POST"];

    [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg] 
                          dataUsingEncoding:NSASCIIStringEncoding]];

    NSURLResponse *response;
    NSError *error;

    if ([NSURLConnection sendSynchronousRequest:request 
                              returningResponse:&response error:&error] != nil)
        NSLog(@"Posted to Twitter successfully.");
        else 
            NSLog(@"Error posting to Twitter."); 
}  

但即使我的控制台说帖子成功,它仍然没有发生。

谁能帮我找出问题所在?,谢谢。

【问题讨论】:

  • 您需要检查返回的响应对象。连接成功并不意味着请求的操作成功。

标签: objective-c ios4 twitter


【解决方案1】:

虽然 twitter 现在只有 O-AUTH 身份验证,所以你不能再简单地通过他们的 REST 服务发布信息了。

您可能需要重新集成他们的新 OAUTH 服务。

更新:

这里是 OAUTH 示例的链接: Twitter - OAUTH

我需要做的是创建一个 WebUI 视图,以便通过 twitter 现在强制执行的愚蠢步骤。在发出身份验证请求(绑定到在 twitter 中创建的应用程序)后,我的会话被创建,我可以从那里发布消息。

不像以前的 REST 服务那样用户友好:/

【讨论】:

  • 不知道。将搜索有关 OAUTH 身份验证或实际 Twitter 教程的一些信息。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
  • 1970-01-01
  • 2014-06-07
  • 1970-01-01
  • 2015-08-05
  • 2013-09-02
  • 1970-01-01
相关资源
最近更新 更多