0

我正在实现转推功能,但在我的 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;
    }

  });
}];

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

4

3 回答 3

1

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

IE

SLRequest *twitterRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/retweet/%@.json",@"490794578250059776"]] parameters:nil];
于 2013-10-07T18:37:24.503 回答
0

安装了这个


   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"]];


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

于 2013-10-07T07:42:09.363 回答
0

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

// 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-10-09T11:12:00.013 回答