簡體   English   中英

SLRequest - Twitter返回代碼215(錯誤的身份驗證數據)

[英]SLRequest - Twitter returns code 215 (Bad authentication data)

我在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];
        }
    }];
}

}

好的,我有答案! 問題是其他iPhone的帳戶數據不完整 - 您必須在設置應用中填寫用戶名和密碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM