Created
April 3, 2015 12:02
-
-
Save mickmaccallum/1cf2f8e6d3f27681bce1 to your computer and use it in GitHub Desktop.
Get Tweets for certain user in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let username = "myHandle" // Put Twitter handle without @ here. | |
let accountStore = ACAccountStore() | |
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter) | |
accountStore.requestAccessToAccountsWithType(accountType, options: nil) { granted, error in | |
if granted == true { | |
if let account = accountStore.accountsWithAccountType(accountType).first as? ACAccount { | |
let finalURL = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + username + "&count=100" | |
let request = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: .GET, URL: NSURL(string: finalURL)!, parameters: nil) | |
request.account = account | |
request.performRequestWithHandler { data, response, requestError in | |
var parseError: NSError? | |
if let parsedData = NSJSONSerialization.JSONObjectWithData(data, options: .allZeros, error: &parseError) as? [AnyObject] { | |
println(parsedData) | |
} else { | |
// coundn't parse JSON. | |
} | |
} | |
} else { | |
// couldn't get logged in user | |
} | |
} else { | |
// user wasn't logged in. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment