Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.58 KB | None | 0 0
  1. import Accounts
  2. import Social
  3. import SwiftyJSON
  4.  
  5. let accountStore : ACAccountStore = ACAccountStore()
  6.  
  7. let accountType = self.accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
  8.  
  9. self.accountStore.requestAccessToAccounts(with: accountType, options: nil, completion: {(success, error) in
  10.     if (success) {
  11.         guard let accountArray = self.accountStore.accounts(with: accountType)
  12.             else {
  13.             // Handle if there is no array for accounts here
  14.             print("Error loading accounts")
  15.         }
  16.        
  17.         if (accountArray.count) > 0 {
  18.             // Get a twitter account - usually the last one, doesn't have to be
  19.             // but this application isn't smart enough to choose.
  20.             let twitterAccount = accountArray.last as? ACAccount
  21.             let params = ["q": "#blockchain", "result_type": "popular"]
  22.             let queryURL = URL(string: "https://api.twitter.com/1.1/search/tweets.json")
  23.            
  24.             let getRequest = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: SLRequestMethod.GET, url: queryURL, parameters: params )
  25.            
  26.             getRequest?.account = twitterAccount
  27.            
  28.             getRequest?.perform(handler: {(responseData, urlResponse, error) in
  29.                 if let err = error {
  30.                     print("Error : \(err.localizedDescription)")
  31.                 }
  32.                
  33.                 let twitterData = JSON(data: responseData!)
  34.                 print(twitterData)
  35.             })
  36.         }
  37.     } else {
  38.        
  39.     }
  40. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement