Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift4: Callback URL not approved for this client application

Tags:

ios

swift

twitter

i'm using swift4: i want to login to the app with twitter, but when i presses login with twitter button i got this error:

Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings" UserInfo={NSLocalizedDescription=Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings} error: Optional("Request failed: forbidden (403)")

i'd followed this documentation and set all plist variables and app delegate also, this is my code in login page:

@IBAction func loginWithTwitter(_ sender: Any) {

    TWTRTwitter.sharedInstance().logIn(completion: {
        (session, error) in
        if let sess = session {
            print("session: ",sess.authToken, sess.authTokenSecret, sess.userID, sess.userName)
            self.loginWithTwitter(twitter_id: sess.userID, name: sess.userName)
        } else {
            print("error: ", error?.localizedDescription as Any)
        }
    })
}

func loginWithTwitter(twitter_id: String, name: String) {
    self.deviceMac = UIDevice.current.identifierForVendor!.uuidString
    KRProgressHUD.show(withMessage: "انتظر ....")
    API.loginWithTwitter(mac:self.deviceMac, twitter_id: twitter_id, name: name, token: self.token) { (error: Error?, success: Bool, value: Any) in
        if success {
            KRProgressHUD.dismiss()
            let json = JSON(value)
            print(json)
            if(json["token"] != "") {
                let token = json["token"].string
                let def = UserDefaults.standard
                def.set(token, forKey: "token")
                def.synchronize()

                Common.setIfTwitterLogin(login: token!)
                let homeViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController

                self.present(homeViewController, animated: false, completion: nil)
            } else {
                self.errorLable.text = "عذرا لقد حدث خطأ حاول مره أخري"
            }
        } else {
            KRProgressHUD.dismiss()
            self.errorLable.text = "عذرا لقد حدث خطأ حاول مره أخري"
            if Connectivity.isConnectedToNetwork(){
                print("Internet Connection Available!")
            }else{
                Common.showToast(messsage: "الرجاء التحقق من إتصالك بالإنترنت", view: self.view)
            }
        }
    }
}

and

class func loginWithTwitter(mac:String, twitter_id: String, name: String, token: String, completion: @escaping (_ error: Error?, _ success: Bool,_ value: Any) -> Void) {

    let loginURL = URLs.loginWithTwitter

    let loginParameters = [
        "mac": mac,
        "twitter_id": twitter_id,
        "token": token,
        "name": name]

    print(loginURL, loginParameters)
    Alamofire.request(loginURL, method: .post, parameters: loginParameters, encoding: URLEncoding.default, headers: nil)
        .responseJSON { reponse in
            switch reponse.result {
            case .failure(let error):
                print("error: ", error)
                completion(error, false, "")
            case .success(let value):
                completion(nil, true, value)
            }
    }
}

i'd set a call back url in twitter developer app setting, any one know what is the problem?

like image 822
Al-shimaa Adel Avatar asked Jun 13 '18 08:06

Al-shimaa Adel


1 Answers

In your twitter dashboard Go to: https://apps.twitter.com Go into the settings tab and add following Callback URL.

twitterkit-<consumerKey>://

i.e. twitterkit-4bvXXXXXXNFfOXXwrXXXXXXmT://

like image 108
Shahrukh Avatar answered Nov 16 '22 00:11

Shahrukh