0
我一直在嘗試使用內置的iOS帳戶和Twitter框架檢索Twitter用戶數據。Twitter SLRequest驗證錯誤
我正在成功訪問手機上的用戶帳戶。但是,在向Twitter發送SLRequest時,我收到未經驗證的錯誤。我的印象是,將用戶ACCount分配給twitter SLRequest.account滿足了必要的OAuth部分。
代碼從測試項目中,我已經建立了
任何反饋是非常感謝!
VAR accountsArray = AnyObject VAR帳戶= ACAccount()
override func viewDidLoad() {
super.viewDidLoad()
let accountStore: ACAccountStore = ACAccountStore()
let twitterAccountType: ACAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
let url = NSURL(string: "https://api.twitter.com/1.1/users/show.json")
let params: NSDictionary = ["field": "user_id, screen_name"]
accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil, completion: { (success, error) -> Void in
if success {
let account = accountStore.accountsWithAccountType(twitterAccountType)
if let userAccount = account.first as? ACAccount {
self.accountsArray.append(userAccount)
let twitterRequest = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: SLRequestMethod.GET, URL: url, parameters: params as [NSObject : AnyObject])
從我已經找到我認爲下面的線覆蓋了Twitter的API版本的OAuth要求1.1
twitterRequest.account = userAccount
twitterRequest.performRequestWithHandler({ (responseData : NSData?, urlResponse : NSHTTPURLResponse?, error : NSError?) -> Void in
print("data : \(responseData)")
if let response = responseData {
var dict = NSDictionary()
do {
dict = try! NSJSONSerialization.JSONObjectWithData(response, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
}
print(dict)
} else if error != nil {
print("Error : \(error)")
}
})
}
} else if (error != nil) {
print("nooope")
}
})
}
}
請告訴我返回從字典中:
{
errors = (
{
code = 50;
message = "User not found.";
}
);
}