android - 在 android 中集成 instagram 身份验证

标签 android instagram-api

我正在构建一个使用 instagram API 的 android 应用程序,我想知道是否有一种解决方案可以避免构建 api(重定向 uri)来处理来自 instragram 身份验证端点的重定向,以便为 android 客户端检索 token 。

最佳答案

我想你可以用他们的 Client side (implicit) authentication 来实现.检查文章末尾的部分。

Once the user has authenticated and then authorized your application, Instagram redirects them to your redirect_uri with the access_token in the url fragment. It will look like this:

http://your-redirect-uri#access_token=ACCESS-TOKEN

Simply grab the access_token off the URL fragment and you’re good to go. If the user chooses not to authorize your application, you’ll receive the same error response as in the explicit flow.

关键部分是您必须定义重定向uri,但在这种情况下它必须无效。例如,如果您使用 www.google.com 作为重定向 uri,在身份验证后用户将被重定向到

http://www.google.com#access_token=ACCESS-TOKEN

此时,您必须让用户继续前进。相反,捕获重定向并解析 URI 字符串,以便您可以获得访问 token 。

如果您的导航发生在 WebView 内部,这可能发生在 shouldOverrideUrlLoading() 回调(来自 WebViewClient)中:

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.startsWith("http://www.google.com") { // redirect uri!
        String accessToken = ... // get token from url
        return true; // don’t load the page
    }
    return false;
}

这会有些痛苦,例如错误处理,但是嘿,如果他们有客户端身份验证,它应该也适用于您。

关于android - 在 android 中集成 instagram 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41007386/

相关文章:

android - 仅限华为手机上的复数 NotFoundException

android - 尝试在 android 中添加两个 setContentView 时出现空指针异常

java - 从 Eclipse 解密保存的密码

Instagram/v1/tags/{tag-name}/media/recent 端点不会在分页 block 中返回 min_tag_id

不同 API 上的 Android 绘画问题

android - 找不到 RippleDrawable

instagram - 1080x1080 照片通过 Instagram API

json - 有关用于 Swift 3 的 Instagram API 更改的问题。纬度和经度,按#hastag 搜索

Instagram API,新应用待审核

python - 当我使用 python-instagram 库时,instagram api 不断引发 'You must provide a client_id' 异常