【问题标题】:Instagram redirect URI only handled as Android intent when using custom schemeInstagram 重定向 URI 仅在使用自定义方案时作为 Android 意图处理
【发布时间】:2016-09-22 03:57:12
【问题描述】:

我正在尝试在我的 Android 应用中通过 Instagram 进行身份验证。正如其他人拥有noticed 一样,当我在 Instagram 仪表板中分配重定向 URI 时,我可以使用 http 或 https 作为方案。但是,当发送重定向时,我的应用无法识别它,并且我的浏览器会尝试正常解析 URI。

这是有趣的一点:当我使用我的网页作为重定向 URI,并且在页面的代码中强制重定向到具有自定义方案(如“myapp”而不是“http”)的 URI 时,应用程序只识别它美好的。当然,我在这个过程中丢失了所有的身份验证细节,所以这在很大程度上是无用的,但它确实指出了该方案是罪魁祸首(当然这是我无法改变的一件事)。

这是我的意图过滤器:

<intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="https"/>
            <data android:host="oauth2redirect.aggro"/>
        </intent-filter>

我尝试了不同的数据元素组合,例如添加 pathPrefix,但没有结果。我可以让应用程序接收意图的唯一方法是将方案更改为 http 或 https 以外的其他内容。

想出一些脚本在页面上运行以通过重定向转发必要的标头和有效负载,是否有解决方法?

编辑:仍在寻找解决方法。但是,它确实 look like 这是 Chrome for Android 中链接的预期行为。

【问题讨论】:

    标签: android redirect android-intent oauth instagram


    【解决方案1】:

    好吧,对于同一条船上的任何人,这就是我最终要做的事情:我使用我的自定义方案和 URI(即 myapp://oauth2redirect 或您想要的任何唯一 URI)设置我的意图过滤器。然后对于重定向 URI,我将其设置为我的个人网页。在页面的正文中,我包含了以下脚本:

    <script type="text/javascript">
        var target = "myapp://oauth2redirect/?" + window.location.search.substring(1);
        window.location.href = target;
    </script>
    

    这解决了问题,尽管这意味着维护您为此目的使用的任何页面。除非 Instagram 允许输入自定义方案,否则我看不到其他选项。

    【讨论】:

    • 这种变通方法也为我解决了问题。但是我不得不改变 window.location.search.substring(1);到 window.location.hash.substring(1);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2012-07-10
    相关资源
    最近更新 更多