2011-11-22 99 views
1

我在創建和保存iOS5上ACAccountStore的新Twitter帳戶時遇到問題。在iOS5上創建twitter ACAccount時出錯:NSURLErrorDomain錯誤-1012

執行完初始帳戶的所有步驟後,ACAccountStore'ssaveAccount:withCompletionHandler:返回NSURLErrorDomain error -1012

有沒有人有類似的問題?

我的代碼示例如下使用requestToken來初始化ACAccountCrendential。此對象是一個OAToken(ShareKit對象),使用令牌和祕密在完成OAuth後收到的密碼初始化。

ACAccountStore *store = [[[ACAccountStore alloc] init] autorelease]; 
    ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
    ACAccount *account = [[[ACAccount alloc] initWithAccountType:twitterAccountType] autorelease]; 

    account.username = @"twitterusername"; 
    account.credential = [[[ACAccountCredential alloc] initWithOAuthToken:requestToken.key tokenSecret:requestToken.secret] autorelease]; 
    [store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if (granted) { 
      [store saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) { 
       if (success) { 
        NSLog(@"TWITTER ACCOUNT CREATED SUCCESSFULLY!"); 
       } 
       else{ 
        NSLog(@"ERROR creating twitter account: %@", [error description]); 
       } 
      }]; 
     } 
    }]; 

奇怪的是,蘋果的Accounts Framework Reference表明saveAccount:withCompletionHandler:嘗試執行OAuth本身:使用其憑據

如果帳戶類型支持認證和帳戶未通過身份驗證,該帳戶被認證 。如果認證成功,則保存帳戶;否則,它不會被保存。

我覺得很奇怪,因爲用戶無法通過輸入用戶名/密碼直接與服務器進行身份驗證。

我也試圖與我的應用程序的消費者密鑰和消費者祕密進行初始化ACAccountCredential,具有相同的結果(與NSURLErrorDomain error -1012.失敗)

有關這個主題的任何指導,將不勝感激!

謝謝。

回答

2

我在使用ACAccount添加Twitter帳戶時遇到同樣的問題。但是,我能夠使用授權的OAuth訪問令牌和訪問令牌密鑰成功創建帶有ACAccount的Twitter帳戶,而不是使用者密鑰和使用者密鑰。 (dev.twitter.com/apps->Twitter->OAuth->OAuth設置 - >訪問令牌和訪問令牌機密)這意味着您仍然必須使用OAuth庫來獲取授權的訪問令牌和訪問令牌時的祕密該用戶正在添加一個Twitter帳戶。

更新:您可以看到Twitter如何建議您將現有帳戶遷移到iOS5系統帳戶here。該鏈接爲我提供瞭如何添加ACAccount的最佳示例。

相關問題