【问题标题】:Instagram redirect url issue in swiftInstagram 快速重定向 url 问题
【发布时间】: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


【解决方案1】:

您需要在应用的 Info.plist 中提及要使用的 URI 方案。完成后,您可以使用 URI 方案,例如 com.myappid.name:/myCallback

Info.plist-> Setting URI Scheme

【讨论】:

  • 表示哪个app id instagram developer app 或其他?
  • 您只能使用您的应用 ID(您的包标识符)。
  • com.Hemsandhub.InstagramDemo:/hemsandhub.auth0.com/login/callback 喜欢这样吗??
  • 我仍然重定向到那个 url 我无法在我的应用程序中返回
  • 你能告诉我 ios 的 insta gram 的重定向 uri 格式吗
【解决方案2】:

试试这个。例如你想打开一个 Instagram 应用:

https://stackoverflow.com/a/33932755/4476989 或者也阅读这篇https://github.com/shyambhat/InstagramKit/issues/237

 var instagramHooks = "instagram://user?username=johndoe"
    var instagramUrl = NSURL(string: instagramHooks)
    if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
    {  
        UIApplication.sharedApplication().openURL(instagramUrl!)

     } else {
        //redirect to safari because the user doesn't have Instagram
        UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    相关资源
    最近更新 更多