Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Accounts
- import Social
- import SwiftyJSON
- let accountStore : ACAccountStore = ACAccountStore()
- let accountType = self.accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
- self.accountStore.requestAccessToAccounts(with: accountType, options: nil, completion: {(success, error) in
- if (success) {
- guard let accountArray = self.accountStore.accounts(with: accountType)
- else {
- // Handle if there is no array for accounts here
- print("Error loading accounts")
- }
- if (accountArray.count) > 0 {
- // Get a twitter account - usually the last one, doesn't have to be
- // but this application isn't smart enough to choose.
- let twitterAccount = accountArray.last as? ACAccount
- let params = ["q": "#blockchain", "result_type": "popular"]
- let queryURL = URL(string: "https://api.twitter.com/1.1/search/tweets.json")
- let getRequest = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: SLRequestMethod.GET, url: queryURL, parameters: params )
- getRequest?.account = twitterAccount
- getRequest?.perform(handler: {(responseData, urlResponse, error) in
- if let err = error {
- print("Error : \(err.localizedDescription)")
- }
- let twitterData = JSON(data: responseData!)
- print(twitterData)
- })
- }
- } else {
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement