【问题标题】:SLRequest - Twitter returns code 215 (Bad authentication data)SLRequest - Twitter 返回代码 215(错误的身份验证数据)
【发布时间】:2013-10-05 13:36:51
【问题描述】:

我有上传照片的应用程序,比如 Instagram 应用程序。首先我的应用上传照片并返回链接。然后在状态消息中发送链接。当我在我的 iPhone 上进行测试时,一切正常,但是当我在另一部 iPhone 上进行测试时,twitter 返回代码 215 错误的身份验证数据。有什么想法可能是错的吗?谢谢回复。

- (void)tweet:(NSString *)identifier withCompletionHandler:(void (^)())completionHandler {
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) {
        if (identifier) {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];
                NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Check out this great flick on BLA BLA %@", [BLA_URL stringByAppendingFormat:@"/%@/%@", @"flick", identifier]]
                                                                 forKey:@"status"];

                SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                                        requestMethod:SLRequestMethodPOST
                                                                  URL:url
                                                           parameters:dict];
                [request setAccount:[accountsArray lastObject]];
                [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                    if ([urlResponse statusCode] == 200) {
                        NSLog(@"TWEEET!");

                    }
                    else { 
                        NSError *jsonError;
                        id data = [NSJSONSerialization JSONObjectWithData:responseData
                                                                  options:NSJSONReadingMutableLeaves
                                                                    error:&jsonError];

                        dispatch_async(dispatch_get_main_queue(), ^{
                            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter response"
                                                                                message:[NSString stringWithFormat:@"%d S: %d %@", [error code], [urlResponse statusCode], data]
                                                                               delegate:self
                                                                      cancelButtonTitle:@"Ok"
                                                                      otherButtonTitles:nil];
                            NSLog(@"NOOO TWEEET!");
                            [alertView show];
                            completionHandler();
                        });
                    }
                }];
...

及预检功能:

- (IBAction)twitterButtonTapped:(id)sender {
if ([self.twitterButton isSelected]) {
    [self.twitterButton setSelected:NO];
}
else {
    [self.twitterButton setSelected:YES];

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if (!granted) {
            [self.twitterButton setSelected:NO];

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter access"
                                                                message:@"Please make sure you have allowed twitter for BLA BLA in your Settings."
                                                               delegate:self
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil];
            [alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
        }
    }];
}

}

【问题讨论】:

  • 我遇到了同样的问题。类似的代码一直有效,直到我不得不切换到 API v 1.1
  • 其他 iPhone 是否在设置中设置了 Twitter 帐户?对话框是否显示在要求您授予访问权限的位置?
  • 是的,其他 iPhone 有大约 10 个 Twitter 帐户。是的,当无法访问时会出现对话。当有人点击“在 Twitter 上分享”按钮时,我编写了预检查代码。我刚刚添加了这段代码。
  • 嗯,我遇到了同样的错误,但我意识到我的代码在 accountStore 被初始化之前被调用了。这显然不是你的问题。也许在 performRequestWithHandler 处设置一个断点并检查变量的内容?
  • 我已经检查了一切,但没有成功。

标签: ios objective-c cocoa twitter slrequest


【解决方案1】:

好的,我知道了!问题是其他 iPhone 的帐户数据不完整 - 这意味着您必须在“设置”应用中填写用户名和密码。

【讨论】:

  • 需要明确的是,对于任何有同样问题的人,仅登录 Twitter 应用程序是不够的。您还必须在 iPhone 设置应用程序中输入您的帐户信息和密码。修复了我发帖失败的问题。我觉得在 iOS6 中不是这样,之前登录 Twitter 应用程序似乎已经足够好了。但是无法确认,因为我所有的设备都已升级。
猜你喜欢
  • 2012-09-22
  • 1970-01-01
  • 2015-07-10
  • 2013-01-02
  • 2019-07-24
  • 2015-06-30
  • 2020-11-05
  • 2015-09-23
  • 2016-04-18
相关资源
最近更新 更多