如何使用OAuth2Swift获取Instagram的access_token

我尝试了所有可能的选项,但redirectURI不返回access_token 。 我添加了一个callbackURI,我可以从用户请求login并授予访问权限,但在callback中出现此错误。

我在开发者门户网站上注册了这个URI,它似乎正常工作:

 http://oauthswift.herokuapp.com/callback/instagram 

当我尝试使用以下方式在Web浏览器上进行身份validation时:

 https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=http://oauthswift.herokuapp.com/callback/instagram&response_type=token 

我得到访问令牌:

ACCESS_TOKEN

当我尝试使用OAuthSwift ,我得到这个错误,redirectURI不包括access_token ,尽pipeDocs说:

文件

这是错误的:

serverError [没有access_token,没有代码,服务器没有提供错误]

这是我的代码如下:

  // MARK: Instagram func doOAuthInstagram(_ serviceParameters: [String:String]){ let oauthswift = OAuth2Swift( consumerKey: serviceParameters["consumerKey"]!, consumerSecret: serviceParameters["consumerSecret"]!, authorizeUrl: "https://api.instagram.com/oauth/authorize", responseType: "token" ) let state = generateState(withLength: 20) self.oauthswift = oauthswift oauthswift.authorizeURLHandler = getURLHandler() let _ = oauthswift.authorize( withCallbackURL: URL(string: "http://oauthswift.herokuapp.com/callback/instagram")!, scope: "likes+comments", state:state, success: { credential, response, parameters in self.showTokenAlert(name: serviceParameters["name"], credential: credential) self.testInstagram(oauthswift) }, failure: { error in print(error.description) } ) }