2012-08-24 39 views
2

我試圖將一個Twitter帳戶保存到ACAccountStore爲什麼在保存Twitter ACAccount時出現此錯誤?

我使用MPOauth(此功能完美,我可以驗證併發布消息)對用戶進行身份驗證,當我收到訪問令牌和訪問令牌密碼時,我繼續保存該帳戶。

首先,我拆分了令牌訪問權限,只取自己的令牌,而不是用戶ID。這是我的代碼

if ([username length] > 0 && [token length] > 0 && [secret length] > 0) { 

    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
    ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType]; 
    ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret]; 

    [account setCredential:credentials]; 
    [account setUsername:username]; 

    [accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) { 

     if (success) { 

      NSLog(@"the account was saved!"); 

     } else { 

      NSLog(@"the account was NOT saved"); 
     } 

     [accountStore release]; 
     [account release]; 
     [credentials release]; 
    }]; 
} 

但從未工作後,我得到這個

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" 

,我讀了這個響應錯誤驗證對Twitter上的數據,事情是由iOS5的框架保存前完成該帳戶。

我已經閱讀this reponse和帖子Twitter

出了什麼問題?

回答

0

如果令牌是OAToken你應該與此

ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuthToken:token.key tokenSecret:token.secret]; 

替換此

ACAccountCredential *credentials = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:token]; 

應該分別通過關鍵&祕密作爲第一和第二參數。

+0

不,它不是OAToken對象,我將令牌和祕密作爲NSString對象傳遞。無論如何,我會遇到同樣的問題,對吧? – emenegro

+0

已更新的答案。 – msk

+0

Arrrrrrghhhhhhh,我很愚蠢T_T我將'token'和'token'作爲參數傳遞,而不是'token'和'secret'。無論如何,這並沒有解決問題:-( – emenegro

相關問題