Comments (13)
Access token
// save session
let accessToken = swifter.client.credential.accessToken {
let key = accessToken.key // String
let secret = accessToken.secret // String
// save the key and secret to Keychain
}
// load session
let key = ... // load the key from Keychain
let secret = ... // load the secret from Keychain
let accessToken = SwifterCredential.OAuthAccessToken(key: key, secret: secret)
let credential = SwifterCredential(accessToken: accessToken)
let swifter = Swifter(consumerKey: "", consumerSecret: "")
swifter.client.credential = credential
ACAccount
// save session
if let account = swifter.client.credential.account {
let identifier = account.identifier // String
// save identifier to Keychain
}
// load session
let identifier = ... // load the identifier by Keychain
let account = ACAccountStore().accountWithIdentifier(identifier)
let credential = SwifterCredential(account: account)
let swifter = Swifter(consumerKey: "", consumerSecret: "")
swifter.client.credential = credential
from swifter.
Hi, thanks for your time to answer my question.
I've got an error when I tried to load the session
HTTP Status 400: Bad Request, Response: {"errors":[{"message":"Bad Authentication data","code":215}]}
if I change the codes when I load the session to this
let swifter = Swifter(consumerKey: myConsumerKey, consumerSecret: myConsumerSecret)
swifter.client.credential = credential
I got this error
HTTP Status 401: Unauthorized, Response: {"errors":[{"message":"Could not authenticate you","code":32}]}
do you know where is the problem?
from swifter.
umm.
there is a possibility that you tweet without setting the write permissions.
https://apps.twitter.com/app/YOUR_APP_ID/permissions
Note: https://dev.twitter.com/overview/api/response-codes
from swifter.
Hello s-aska,
I have tried to update twitter session with your code, here is mine :
let key = "my-twitter-from-keychain"
let secret = "my-twitter-secret-from-keychain"
let accessToken = SwifterCredential.OAuthAccessToken(key: key!, secret: secret!)
let credential = SwifterCredential(accessToken: accessToken)
self.swifter = Swifter(consumerKey: "my-key", consumerSecret: "my-secret")
swifter.client.credential = credential
But this seem not working properly, like if not call to twitter were done.
Here is my credential :
As you can see, data are nil, can you tell me have i don't do properly please ?
Thanks,
from swifter.
i did this to solve this problem:
if userHelper.fetchUserToken() != nil {
self.swifter.client.credential = userHelper.fetchUserToken()
user = self.userHelper.fetchUserQData()
} else {
self.swifter.authorizeWithCallbackURL(NSURL(string: "some.twitterapp://success")!, success: {
credential, response in
var tmp = self.swifter.client.credential?.accessToken?
self.userHelper.saveUserToken(tmp!)
},failure: failureHandler
)
}
func saveUserToken(data: SwifterCredential.OAuthAccessToken) -> Bool {
var userdata = NSUserDefaults.standardUserDefaults()
userdata.setObject(data.key, forKey: "key")
userdata.setObject(data.secret, forKey: "secret")
userdata.setObject(data.screenName, forKey: "screenName")
userdata.setObject(data.userID, forKey: "userID")
userdata.setObject(data.verifier, forKey: "verifier")
userdata.synchronize()
return true
}
func fetchUserToken() -> SwifterCredential? {
var userdata = NSUserDefaults.standardUserDefaults()
if var tkey = userdata.objectForKey("key") as? String {
if var tsecret = userdata.objectForKey("secret") as? String {
var access = SwifterCredential.OAuthAccessToken(key: tkey , secret: tsecret)
return SwifterCredential(accessToken: access)
}
}
return nil
}
func fetchUserQData() -> NSDictionary {
var userdata = NSUserDefaults.standardUserDefaults()
var data: NSMutableDictionary = NSMutableDictionary()
data["screenName"] = userdata.objectForKey("screenName") as String?
data["userID"] = userdata.objectForKey("userID") as String?
return data
}
i am sure, there are better ways to do that ;)
from swifter.
Hi Alex,
My question was not about how to save usertoken.
My problem is when i restart my app, how do i ask to twitter/swifter to refresh the token with my saved usertoken for dont have to login again anymore ?
Do you succeed to do this ?
from swifter.
i updated my answer above.
acaccount will stay nil.
i didn't get along with it,..
the others nil values are coming with the credentials i saved. so you can use these.
after authentication (twitter webpage) there is now need to login again, until you uninstall the app from your phone or simulator.
from swifter.
Ok Alex, and can you confirm that when you debug the user variable at this line :
user = self.userHelper.fetchUserQData()
You fetch exactly the same data as authorizeWithCallbackURL do please with your tmp var ?
As you can see in my debug picture, only the key and secret have data,
from swifter.
i had to add another piece of code. ;)
actually, you could just copy and paste the code. it will do a couple of steps to get the data and save it for all coming requests, incl authentication call if neccessary.
from swifter.
Thanks for your code ;)
So you confirm that :
var access = SwifterCredential.OAuthAccessToken(key: tkey , secret: tsecret)
return SwifterCredential(accessToken: access)
Does'nt return the fully object whith screenName and userID ? Its not normal isn't it ?
from swifter.
i do not really know if its normal - to be honest i expected this data, too ;) - but during debugging it shows, i need to do a request to get it....
from swifter.
Ok, i will continu to investigate. Thanks for you help !
from swifter.
It's been over an year since the last update of this issue: I believe the school's project is done by now :)
from swifter.
Related Issues (20)
- ErrorResponse Handling HOT 1
- library swiftyJSON error after import swifter in viewcontroller HOT 1
- Fail to authorise HOT 2
- how to embed tweet in swift?
- Documentation/tutorials for Swifter?
- Data instead of JSON - anyone wanna work on this with me? HOT 6
- I want to use `Swifter.authorizeSSO(succees: _, failure: _)` but the authentication page does not appear on the app. just appear Home HOT 6
- 'Swifter' used both as module name and class name is problematic. This breaks debugging HOT 1
- Compilation error on Xcode 13 Beta 4 HOT 1
- Authorize with actual twitter app or website, not with app-internal web view? HOT 1
- needs to update usage documentation for iOS13 & up HOT 1
- Any plans to support cocoapods?
- Any plans to include Twitter v2 API?
- iOS login with twitter has error: CredStore - performQuery - Error copying matching creds HOT 1
- difference between default initializers?
- createSavedSearch method - Could not authenticate you
- [Question] how to use authorizeSSO? HOT 2
- ⚠️ Deprecation notice ⚠️ HOT 9
- Iswifter.ipa
- 'Swifter-Swift.h' file not found & (fatal) could not build module 'Test'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swifter.