gpt4 book ai didi

iphone - 使用 TWRequest 的推特更新给出 403 错误

转载 作者:可可西里 更新时间:2023-11-01 05:01:44 28 4
gpt4 key购买 nike

我正在使用以下代码使用 iOS 5 twitter API 在用户的时间线中发推文

//创建一个帐户存储对象。 ACAccountStore *accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if(granted)
{
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:buttonIndex];
// Create a request, which in this example, posts a tweet to the user's timeline.
// This example uses version 1 of the Twitter API.
// This may need to be changed to whichever version is currently appropriate.


TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"hello this is a tweet" forKey:@"status"] requestMethod:TWRequestMethodPOST];

// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];

// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{

NSString *output = [NSString stringWithFormat:@"%i", [urlResponse statusCode]];
[self performSelectorOnMainThread:@selector(TweetStatus:) withObject:output waitUntilDone:NO];
}];
}
}];

我已经使用这种方法测试应用程序一个多月了,它过去工作正常,没有任何问题。

几周后它开始在以下方法中返回 403 错误。

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
{

NSString *output = [NSString stringWithFormat:@"%i", [urlResponse statusCode]];
[self performSelectorOnMainThread:@selector(TweetStatus:) withObject:output waitUntilDone:NO];
}];

它给出了以下错误:

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x1f8b3250 {NSErrorFailingURLKey=http://api.twitter.com/1/statuses/update.json, NSErrorFailingURLStringKey=http://api.twitter.com/1/statuses/update.json, NSUnderlyingError=0x1ed19f90 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012

我搜索了很多,但找不到解决此问题的方法或真正原因。

请牢记一些可能有助于理解问题的注意事项:

  • 该应用程序用于测试,这意味着我们使用了 Twitter 共享并与其他用户提及了很多。
  • 共享内容并不总是相同的,因此不会出现重复问题,因为我们经常清理时间线。

谢谢

最佳答案

您尝试发送推文的文本必须与您之前发布的推文相似,因此您会收到此错误。根据文档 here , 不能多次发布相同的文本。 enter image description here

编辑:

这也可能取决于他们网站上提到的推文总数。

关于iphone - 使用 TWRequest 的推特更新给出 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13843910/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com