【问题标题】:Twitter iOS GET statuses/home_timeline using ParseTwitter iOS GET statuses/home_timeline 使用 Parse
【发布时间】:2014-07-26 21:47:49
【问题描述】:

这将是我的第一个 iPhone 应用程序,我遇到了一些困难,我认为我可以找到一个教程,但是很遗憾....在互联网上我找不到任何东西。

我正在尝试从已登录用户(使用 Parse 的 Twitter 身份验证登录)那里获取最初的 20 条左右的推文,但我似乎无法让它工作。当我遇到错误时,我在其中设置了一个断点,这就是它所显示的:

我正在考虑完全放弃 Parse 并使用 https://github.com/nst/STTwitter 进行自己的身份验证,但想快速了解是否有一种方法可以简单地做我想做的事情。代码问题在这个 github 上:https://github.com/johndangerstorey/twiz 并在我的 MyLoginViewController.m 文件中概述如下:

NSString *bodyString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/home_timeline.json?screen_name=johnDANGRstorey"];

// Explicitly percent-escape the '!' character.
bodyString = [bodyString stringByReplacingOccurrencesOfString:@"!" withString:@"%21"];

NSURL *url = [NSURL URLWithString:bodyString];
NSMutableURLRequest *tweetRequest = [NSMutableURLRequest requestWithURL:url];
tweetRequest.HTTPMethod = @"GET";
tweetRequest.HTTPBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding];

[[PFTwitterUtils twitter] signRequest:tweetRequest];

NSURLResponse *response = nil;
NSError *error = nil;

// Post status synchronously.
NSData *data = [NSURLConnection sendSynchronousRequest:tweetRequest
                                     returningResponse:&response
                                                 error:&error];

// Handle response.
if (!error) {
    NSLog(@"Response: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
} else {
    NSLog(@"Error: %@", error);
}

感谢您的回复和帮助。

【问题讨论】:

    标签: ios api twitter parse-platform


    【解决方案1】:

    我想通了,GET 请求不需要 .body 或 .method 请求,所以我删除了 tweetRequest.HTTPMethod = @"GET"; tweetRequest.HTTPBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding]; 并且是金色的。

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 2016-02-12
      • 2012-07-10
      • 2011-11-11
      • 2017-03-27
      • 2014-11-13
      • 2016-07-22
      • 1970-01-01
      • 2014-10-28
      相关资源
      最近更新 更多