【发布时间】:2018-08-07 06:23:35
【问题描述】:
我正在为我的 iOS 应用实现 Instagram 登录。我已成功登录,但后来我无法进入我的应用程序,谁能告诉我哪个是 instagram 的有效重定向 URL?这是我的代码:
代码
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
do {
if let url = request.url {
print(url)
if String(describing: url).range(of: "#access_token") != nil {
try InstagramEngine.shared().receivedValidAccessToken(from: url)
if let accessToken = InstagramEngine.shared().accessToken {
print("accessToken: \(accessToken)")
//start
let URl = "https://api.instagram.com/v1/users/self/?access_token=\(accessToken)"
let parameter = [ "access_token" : accessToken ]
// let URl = "https://api.instagram.com/v1/users/self/"
// appInstance.showLoader()
Alamofire.request(URl, method: .get, parameters: parameter, encoding: JSONEncoding.default, headers: nil)
.responseJSON { response in
//appInstance.hideLoader()
print(response.result.value!)
if response.result.isSuccess {
let dict = response.result.value!
do {
var result : [String : AnyObject] = [String : AnyObject]()
let data = try JSONSerialization.data(withJSONObject: dict, options: JSONSerialization.WritingOptions.prettyPrinted)
if let json = NSString(data: data, encoding: String.Encoding.utf8.rawValue){
print(json)
result["result"] = json
if hhSocialDelegate != nil{
hhSocialDelegate.getInstagramLoginResponse(userData : result)
_ = self.navigationController?.popViewController(animated: true)
}
}
}catch let err as NSError{
print(err.debugDescription)
_ = self.navigationController?.popViewController(animated: true)
}
}
}
}
}
}
} catch let err as NSError {
print(err.debugDescription)
_ = self.navigationController?.popViewController(animated: true)
}
return true
}
这是我调用 instagram api 的代码,所以请帮助我解决登录后如何返回我的应用程序的问题。
【问题讨论】:
-
如果您想知道如何避免建造第二组加沙金字塔,请查看风格指南的这一部分:github.com/linkedin/…
标签: ios swift instagram-api