【问题标题】:iOS retweet with SLRequest returns bad URL error带有 SLRequest 的 iOS 转发返回错误的 URL 错误
【发布时间】:2014-07-20 18:07:27
【问题描述】:

我正在实现转推功能,但我在 POST 之后不断收到错误的 URL 错误。 这是我的代码:

SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/retweet/%@.json"] parameters:[NSDictionary dictionaryWithObject:tweetId forKey:@"id"]];

[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
  dispatch_async(dispatch_get_main_queue(), ^{

    if ([urlResponse statusCode] == 429) {
        NSLog(@"Rate limit reached");
        return;
    }

    if (error) {
        NSLog(@"Error: %@", error.localizedDescription);
        return;
    }

  });
}];

有什么想法吗?我错过了什么吗?谢谢!

【问题讨论】:

    标签: ios twitter slrequest


    【解决方案1】:

    我的错。创建请求“...%@.json”时忘记传递字符串。

    SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json",@"490794578250059776"]] parameters:nil];
    

    【讨论】:

      【解决方案2】:

      这个


         SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/retweet/%@.json"] parameters [NSDictionary dictionaryWithObject:tweetId forKey:@"id"]];
      


      试试这个


       SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/retweet/%@.json"] parameters:[NSDictionary dictionaryWithObject:tweetId forKey:@"status"]];
      


      一件事你不能一次又一次地转发相同的消息,它会被视为垃圾邮件 也看到这个link你可能会错过一些东西

      【讨论】:

      • 我试过了,还从链接中查看了你的代码,每次都得到 403。
      • 您是否在您的设备中设置了帐户
      • 我做到了,但我才意识到我做错了什么。实际上,我的代码是正确的,除了我忘记传递字符串 :p
      • 可能是你达到了更新限制,看这个dev.twitter.com/docs/error-codes-responses
      【解决方案3】:

      您应该在请求中附加一个帐户。

      // create a request
      NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
      
      SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                              requestMethod:SLRequestMethodGET
                                                        URL:url
                                                 parameters:@{@"screen_name":@"nst021"}];
      
      // attach an account to the request
      NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
      [request setAccount:[twitterAccounts lastObject]];
      
      // execute the request
      [request performRequestWithHandler:^(NSData *responseData,
                                           NSHTTPURLResponse *urlResponse,
                                           NSError *error) {
          // caution, you're on an arbitrary queue here...
      }
      

      【讨论】:

        猜你喜欢
        • 2013-11-30
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多