How to get Instagram access_token using OAuth2Swift

与世无争的帅哥 提交于 2019-12-11 05:41:04

问题


I tried every possible option, but the redirect URI does not return the access_token. I added a call back URI, I am able to ask from the user to login and give access permission, but I get this error on the call back.

I registered this URI on the Dev portal, and it seems to work fine:

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

When I try to authenticate on a web browser using:

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

I do get the access token:

When I try using OAuthSwift, I get this error and the redirect URI does not include the access_token, dispite what the Docs says:

This is the error:

serverError[No access_token, no code and no error provided by server]

This is my code below:

 // 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)
        }
    )
}

来源:https://stackoverflow.com/questions/40591821/how-to-get-instagram-access-token-using-oauth2swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!