Previously i installed TwitterKit through Fabric. Now i have upgrade it to 3.0.1, Now i am facing problem with composing tweet.
This is my code:
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self.navigationController!) { (result in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
and i am getting following error:
[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "
Desktop applications only support the oauth_callback value 'oob'
/oauth/request_token
" UserInfo={NSLocalizedDescription=
Desktop applications only support the oauth_callback value 'oob'
/oauth/request_token
}
I have already login in my twitter app in my device. When i checking with following condition it always return to else block.
if ([[Twitter sharedInstance].sessionStore hasLoggedInUsers]) {
} else {
}
My requirement is compose tweet from my app. if the user have twitter account in their device otherwise it will ask user to login .
Related
I'm trying to get basic details of a user signing into my app with their Twitter account. I am able to sign them in but not too sure where to go from here.
I'm pretty sure I need to use this get request but am unsure how to structure the request. Am also a little lost which token I include.
I haven't had much experience with the REST API as you could tell. I have Postman set up so if someone could point me in the right direction about accessing the data I could take it from there.
Thanks
#IBAction func twitterSignupPress() {
provider.getCredentialWith(nil) { credential, error in
if error != nil {
print("Error attempting to sign up using Twitter: \(error!)")
} else {
Auth.auth().signIn(with: credential!) { authResult, error in
if error != nil {
print("Error with Twitter signin")
} else {
print("Successful signin using Twitter")
let oAuthCredential = authResult?.credential as! OAuthCredential
print(oAuthCredential.accessToken!) // Prints token
print(oAuthCredential.idToken) // Prints nil
}
}
}
}
}
Was as simple as adding authResult?.additionalUserInfo?.profile
Facebook OAuth error switching from one app ID to another
I worked with contract devs who created the iOS application on another Facebook app ID which i can't control. I am trying to switch it to mine but ran into an error that the token still is using the old App ID. I switched the AppID & the CFBundleURLSchemes in the Plist too. The app compiles with no errors & I am able to get through to FB OAuth but once I sign in, it doesn't go through.
This is the error that I'm receiving
2019-11-15 17:13:20.233275-0600 Imbue[28564:6158269] FBSDKLog: Failed to send AppEvents: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#100) Graph API for app id 472586343541363 called, but token has app id 2470569892995934, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 100;
"fbtrace_id" = "AknZ_YjiTwxrvivhd6v2f_d";
message = "(#100) Graph API for app id 472586343541363 called, but token has app id 2470569892995934";
type = OAuthException;
};
};
code = 400;
(#100) Graph API for app id 472586343541363 called, but token has app id 2470569892995934,
This is the code I have for OAuth
#objc private func authenticateWithFacebook() {
LoginManager().logIn(permissions: ["email", "public_profile"], from: self) { [weak self] (result, err) in
guard let authResult = result else { self?.show(message: FailureMessage.Login.message); return }
if err != nil || authResult.isCancelled {
self?.show(message: FailureMessage.Login.message)
}else {
self?.presentProtectedPage()
}
}
}
I'm not sure what the issue is, have been wrestling with it all day & I feel like it's something super simple. Would appreciate your help as a newbie to swift.
Thanks!
I am writing app with Swift 3 on iOS 10. sharedInstance() method throws errors to console when user deny permissions to account from systems or account is not configured (e.g. "Unable to authenticate using the system account"). Errors are shows on console before enter to closure. I wont shows this errors to users in app e.g. on alert. This is my code:
Twitter.sharedInstance().logIn { (session, error) in
if error != nil {
// print(error?.localizedDescription ?? " ")
return
})
I get this error:
2016-11-29 14:49:09.023 CarReview[1254:31719] [TwitterKit] did encounter error with message "Unable to authenticate using the system account.": Error Domain=TWTRLogInErrorDomain Code=2 "User allowed permission to system accounts but there were none set up." UserInfo={NSLocalizedDescription=User allowed permission to system accounts but there were none set up.}
2016-11-29 14:49:09.024 CarReview[1254:31719] [TwitterKit] No matching scheme found.
2016-11-29 14:49:09.292 CarReview[1254:31719] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
}
I want show users this: "Unable to authenticate using the system account. User allowed permission to system accounts but there were none set up."
I am facing the same issue as in the question.
I have just set the callBack Url into the Twitter App and resolved the issues.
Go to https://apps.twitter.com/app -> Settings -> Callback URL and Update Settings to save.
I'm not sure I understand what you want to do but you probably want to print the result on the main thread:
Twitter.sharedInstance().logIn{(session, error) in
DispatchQueue.main.async{
if error != nil {
print("Failed to login with Twitter / error:", error!.localizedDescription)
}else{
print("succeeded")
}
}
}
OK, I use this code to notify user about some error:
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
if ACAccountStore().accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter).accessGranted {
Twitter.sharedInstance().logIn{
(session, error) in
if error != nil {
self.showAlert(title: "Twitter - Error", message: (error?.localizedDescription)!)
return
}
guard let token = session?.authToken else { return }
guard let secret = session?.authTokenSecret else { return }
let credential = FIRTwitterAuthProvider.credential(withToken: token, secret: secret)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil {
self.showAlert(title: "Firebase (Twitter)", message: (error?.localizedDescription)!)
return
}
self.showAlert(title: "Firebase (Twitter)", message: "Logged to Firebase via Twitter.")
})
}
} else {
showAlert(title: "Twitter - Error", message: "Give access to the system Twitter account.")
}
} else {
showAlert(title: "Twitter - Error", message: "No system accounts set up.")
}
But it isn't what I want:/
You need to use withMethods and specify using the systemAccounts, not webBased or all to use the iOS Twitter settings. The following code is in Swift 3:
twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in
if (error != nil) {
if (session != nil) {
//We have logged into Twitter.
}
}
}
I'm trying to unlink email/password authentication from a user in Swift on iOS. I've read the documentation and managed to link and unlink Facebook authentication without a problem. However, after linking email/password credentials successfully, the providerData object is nil. The providerID is "Firebase" but when I pass that to the unlink code the following error is thrown:
Error Domain=FIRAuthErrorDomain Code=17016 "User was not linked to an account with the given provider." UserInfo={NSLocalizedDescription=User was not linked to an account with the given provider., error_name=ERROR_NO_SUCH_PROVIDER}
The unlink code I'm using is:
let providerId = (FIRAuth.auth()?.currentUser?.providerID)!
print("Trying to unlink:",providerId) // providerId = "Firebase"
FIRAuth.auth()?.currentUser?.unlinkFromProvider(providerId) { user, error in
if let error = error {
print("Unlink error:", error)
} else {
// Provider unlinked from account successfully
print("Unlinked...user.uid:", user!.uid, "Anonymous?:", user!.anonymous)
}
}
Reading the docs and having got it working for Facebook, I expected the providerData array to be populated with something after email authentication. So is my linking code wrong (it doesn't throw an error and appears to work fine)?
My linking code:
let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password)
FIRAuth.auth()?.currentUser!.linkWithCredential(credential) { (user, error) in
if user != nil && error == nil {
// Success
self.success?(user: user!)
dispatch_async(dispatch_get_main_queue(), {
self.dismissViewControllerAnimated(true, completion: nil)
if type == "new" {
print("New user logged in...")
}
if type == "existing" {
print("Existing user logged in...")
}
})
} else {
print("Login error:",error)
self.showOKAlertWithTitle("Login Error", message: error!.localizedDescription)
}
}
Any pointers of how I can modify my approach would be great.
To get the profile information retrieved from the sign-in providers linked to a user, use the providerData property.
if let user = FIRAuth.auth()?.currentUser {
for profile in user.providerData {
// Id of the provider (ex: facebook.com)
let providerID = profile.providerID
}
} else {
// No user is signed in.
}
Calling FIRAuth.auth()?.currentUser?.providerID will result to "firebase".
I have to implement a chat platform using firebase and swift.
I know how to create a user using emailid :
firebase.createUser(emailTextField, password: passwordTextField.text) { (error:NSError!) -> Void in
if (error != nil){
print(error.localizedDescription)
self.displayMessage(error)
} else{
print("New user created")
self.requestUsername()
}
}
But I am not taking any email id or other accounts. I want to create a custom user. For that they have mentioned to use the secure JWT Token and then use this :
let ref = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
ref.authWithCustomToken(AUTH_TOKEN, withCompletionBlock: { error, authData in
if error != nil {
println("Login failed! \(error)")
} else {
println("Login succeeded! \(authData)")
}
})
But they have not mentioned how to generate secure JWT Token in swift.
Anyone know?
Here is the link i referred:
How to login in firebase
As you probably noticed, there is no helper library from Firebase for minting custom tokens on iOS. There is however a set of instructions on how to mint tokens here: https://www.firebase.com/docs/ios/guide/login/custom.html#section-tokens-without-helpers
Minting tokens in a client-app is in general a VERY bad idea, since it requires that you have your Firebase's secret in your app, where any user can find it.