gpt4 book ai didi

ios - 使用 twitter swift 4 登录时出错

转载 作者:行者123 更新时间:2023-11-28 05:56:17 25 4
gpt4 key购买 nike

我想用 twitter 登录,但出现此错误

Request failed: forbidden (403)

只有当我的手机上没有 Twitter 应用程序但如果我的手机上有 Twitter 应用程序时,它才能正常登录,当我使用 Twitter 登录时会发生此错误。

所以为什么我会收到这个错误。

我将此代码用于 Twitter。

@IBAction func twtBtnPressed(_ sender: Any) {

if !Connectivity.isConnectedToInternet() {
Helper.instance.showAlert(self, title: "no conection ", message: "Please check your internet connection", buttonTitle: "Ok", buttonAction: nil)
}else{
Helper.instance.startIndicator2(self, "show", self.lang!, hudd)
print("twitter btn Pressed")
LoginVC.type = "T"

Helper.instance.fetchDataFromTwt(completion: { (id, name, email, image) in
if (id != nil && name != nil && email != nil) {
print("Log in successfully")
print("Login successfully")
print(id!,name!,email!)
APIHelper.apiCore.login_Social(email!, name!, self.self.lang!, "\(id!)","twitter", completion: { (code, message) in
if code == 200 {
print("Api_token: \((message)!)")
Helper.instance.saveApiToken(token: message!)
Helper.instance.startIndicator2(self, "showw", self.self.lang!, hudd)
ProfileVC.twtImage = image
self.performSegue(withIdentifier: "ProfileVC", sender: nil)

}else{
print("Error: \(String(describing: message))")
Helper.instance.showAlert(self, title: "Error", message: message!, buttonTitle: "Ok", buttonAction: { (action) in
Helper.instance.startIndicator2(self, "showw", self.self.lang!, hudd)
})

}
})
}
})

}

}

我使用这段代码从 Twitter 应用程序获取数据。

func fetchDataFromTwt(completion: @escaping (_ id:Int?,_ name:String?,_ email: String?,_ image: String?)-> Void){

TWTRTwitter.sharedInstance().logIn { (session, error) in

if (session != nil) {

print("signed in as \(session!.userName)");
let client = TWTRAPIClient.withCurrentUser()

let request = client.urlRequest(withMethod: "GET", urlString: "https://api.twitter.com/1.1/account/verify_credentials.json", parameters: ["include_entities": "false", "include_email": "true", "skip_status": "true"], error: nil)

client.sendTwitterRequest(request) { response, data, connectionError in

if connectionError != nil {
print("Error: \(String(describing: connectionError))")

}else{
do {
let twitterJson = try JSONSerialization.jsonObject(with: data!, options: []) as! [String:AnyObject]

let name = twitterJson["name"]
let id = twitterJson["id"]
let email = twitterJson["email"]
let image = twitterJson["profile_image_url_https"]

print(name!,id!,email!,image!)

completion(id as? Int, name as? String, email as? String, image as? String)

} catch let jsonError as NSError {
print("json error: \(jsonError.localizedDescription)")

}
}

}

} else {
print("error: \(error!.localizedDescription)");
}
}

}

最佳答案

请检查在您的应用程序的设置菜单上的 Twitter 开发人员门户中分配的回调 URL 是什么。它必须采用 twitterkit-apiKey:// 格式。如果你有像 abc 这样的 apiKey,你应该添加 twitterkit-abc://

关于ios - 使用 twitter swift 4 登录时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51423248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com