【发布时间】:2015-09-17 23:31:00
【问题描述】:
此代码是在 twitter 上搜索主题标签,但它给出了错误提示 无法将“__NSCFDictionary”类型的值转换为“NSArray”
当我使用以下 URL 访问我的家庭时间线时,相同的代码可以正常工作 https://api.twitter.com/1.1/statuses/home_timeline.json
func getTimeLine() {
let accountType = account.accountTypeWithAccountTypeIdentifier(
ACAccountTypeIdentifierTwitter)
self.account.requestAccessToAccountsWithType(accountType, options: nil,
completion: {(success: Bool, error: NSError!) -> Void in
if success {
let arrayOfAccounts =
self.account.accountsWithAccountType(accountType)
if arrayOfAccounts.count > 0 {
let twitterAccount = arrayOfAccounts.last as! ACAccount
let requestURL = NSURL(string:
"https://api.twitter.com/1.1/search/tweets.json?q=%23baseball&result_type=recent%3F")
let parameters = ["count" : "10"]
let postRequest = SLRequest(forServiceType:
SLServiceTypeTwitter,
requestMethod: SLRequestMethod.GET,
URL: requestURL,
parameters: nil)
postRequest.account = twitterAccount
postRequest.performRequestWithHandler(
{(responseData: NSData!, urlResponse: NSHTTPURLResponse!, error: NSError!) -> Void in
var err: NSError?
self.array = NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.MutableLeaves, error: &err) as! [AnyObject**strong text**]
if self.array.count != 0 {
dispatch_async(dispatch_get_main_queue()) {
self.mycollectionView.reloadData()
}
}
})
}
}
else {
println("Failed to access account")
}
})
}
【问题讨论】:
标签: ios swift xcode6 twitter-oauth