【问题标题】:Swift 2 OAuth with Instagram can't open the Instagram app带有 Instagram 的 Swift 2 OAuth 无法打开 Instagram 应用
【发布时间】:2015-12-28 23:18:32
【问题描述】:

我正在尝试从我自己的 iOS 访问 Instagram 应用程序以进行 OAuth 注册。我有以下代码,它正在通过 Safari 访问 Instagram,但如果它在手机上,我希望打开该应用程序。还在寻找一种从 Instagram 为我的应用获取身份验证令牌的方法。

这是我的代码:

func startOAuth2Login()
{
....
    let authPath:String = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=grokInstagram://?aParam=paramVal&response_type=code"

    var instagramHooks = "instagram://app"
    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
        print("didn't have it")
        UIApplication.sharedApplication().openURL(NSURL(string: authPath)!)
    }
....

【问题讨论】:

    标签: ios oauth swift2 instagram-api


    【解决方案1】:

    iOS 9 对 URL 方案的处理做了一个小改动。您必须将您的应用使用Info.plist 中的LSApplicationQueriesSchemes 键调用的网址列入白名单。

    更多:http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html

    【讨论】:

    • 您知道如何从应用程序中获取 OAuth2 的授权令牌并返回到我的应用程序吗?
    • 我不是 OAuth 的大师。但我相信,回到你的应用程序后,这里需要的信息Appdelegate.hfunc application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {请查看。更多关于 Instagram API:instagram.com/developer/authentication
    猜你喜欢
    • 2015-05-07
    • 2015-11-03
    • 1970-01-01
    • 2019-05-27
    • 2012-10-20
    • 1970-01-01
    相关资源
    最近更新 更多