Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios InstagramKit从URL接收到的验证访问令牌不';行不通_Ios_Swift_Instagram_Instagram Api - Fatal编程技术网

Ios InstagramKit从URL接收到的验证访问令牌不';行不通

Ios InstagramKit从URL接收到的验证访问令牌不';行不通,ios,swift,instagram,instagram-api,Ios,Swift,Instagram,Instagram Api,我试图使用Shyambhat的InstagramKit(来自开发分支),但我无法让receivedValidAccessTokenFromURL方法工作 目前我正在使用swift 3.0,代码如下所示(用于测试目的) 我在info.plist中设置了以下内容 InstagramAppClientId:“myid” InstagramAppRedirectURL:' 出于某些原因,instagram不再允许重定向url为app://了。 当我对request.url进行调试时。这向我展示了以下几点

我试图使用Shyambhat的InstagramKit(来自开发分支),但我无法让
receivedValidAccessTokenFromURL
方法工作

目前我正在使用swift 3.0,代码如下所示(用于测试目的)

我在info.plist中设置了以下内容

InstagramAppClientId:“myid”

InstagramAppRedirectURL:'

出于某些原因,instagram不再允许重定向url为app://了。 当我对request.url进行调试时。这向我展示了以下几点

https://api.instagram.com/oauth/authorize/?client_id=myid&redirect_uri=http%3A//example.com&response_type=token&scope=comments%20relationships%20likes%20follower_list


我希望这里有人有使用此库的经验,可以帮助我。

InstagramKit Swift 3.0获取访问令牌:

Info.plist(已添加)


控制台结果我已经弄明白了。我所做的如下

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        do {
            if let url = request.url {
                if (String(describing: url).range(of: "access") != nil){
                    try engine.receivedValidAccessToken(from: url)

                if let accessToken = engine.accessToken {
                    NSLog("accessToken: \(accessToken)")
                }
                }
            }
        } catch let err as NSError {
            print(err.debugDescription)
        }
        return true
    }

我检查url是否包含访问令牌如果包含,那么我将让引擎实际获取访问令牌。出现错误的原因是,当您第一次打开应用程序时,它试图获取访问令牌,但该令牌不可用。

是否需要重定向到另一个应用程序?在尝试调用
receivedValidAccessToken
命令
error Domain=Foundation.\u genericObjectError code=0”(null)时,它会出现以下错误
相同。有什么想法吗?对不起,我不明白你的问题。此代码不起作用?我得到错误域=Foundation.\u GenericObjCError code=0“(null)”我检查了URL,访问令牌在那里。。。但是receivedValidAccessToken函数失败。
<key>InstagramAppClientId</key>
<string>3ewqrewr23453243244qwrqwefwefgw42</string>
<key>InstagramAppRedirectURL</key>
<string>https://www.instagram.com/</string>
import UIKit
import InstagramKit

class ViewController: UIViewController {

var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
   // deleteChache()
    initWebView()
}
func deleteChache() {
    URLCache.shared.removeAllCachedResponses()
    if let cookies = HTTPCookieStorage.shared.cookies {
        for cookie in cookies {
            HTTPCookieStorage.shared.deleteCookie(cookie)
        }
    }
}

}

// MARK: UIWebView

extension ViewController: UIWebViewDelegate {

func initWebView() {

    webView = UIWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
    webView.delegate = self
    view.addSubview(webView)
    authorizationRequestInWebView()
}

func authorizationRequestInWebView() {


    let url = InstagramEngine.shared().authorizationURL()
    let request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10.0)
        webView.loadRequest(request)
}

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

    do {
        if let url = request.url {
            try InstagramEngine.shared().receivedValidAccessToken(from: url)

            if let accessToken = InstagramEngine.shared().accessToken {
                NSLog("accessToken: \(accessToken)")
            }
        }
    } catch let err as NSError {
        print(err.debugDescription)
    }
    return true
}
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        do {
            if let url = request.url {
                if (String(describing: url).range(of: "access") != nil){
                    try engine.receivedValidAccessToken(from: url)

                if let accessToken = engine.accessToken {
                    NSLog("accessToken: \(accessToken)")
                }
                }
            }
        } catch let err as NSError {
            print(err.debugDescription)
        }
        return true
    }