首页 > 解决方案 > 登录 Instagram 时出错(禁用 Cookie) - React Native WebView

问题描述

我的应用程序使用 Instagram OAuth,它从这个 url 打开 Instagram 登录页面:

" https://www.instagram.com/oauth/authorize/client_id= ${clientId}&redirect_uri=${redirectUrl}&response_type=${responseType}&scope=${scopes.join('+')}"

在这里,用户可以输入他们的用户名和密码,然后按登录按钮。然而,他们第一次进入 Instagram 时会抛出一个错误。第二次打开链接时,它会包含用户数据并将用户导航到应用程序的主屏幕。

错误

无法加载此页面。如果您在浏览器中禁用了 cookie,或者您正在以隐私模式浏览,请尝试启用 cookie 或关闭隐私模式,然后重试您的操作。

Instagram 错误 - Cookie 已禁用

这是 webView 渲染函数;

render() {
    const { uri } = this.state;

    if(this.state.loading){
        return <SpinnerComponent size={'small'}/>;
    }

    return (
        <View style={{ flex: 1 }}>
            <WebView 
                startInLoadingState
                onNavigationStateChange={this.onNavigationStateChange.bind(this)}
                source={{ uri }}
                style={{flex: 1}}
            />
        </View>
    );
}

笔记

我正在使用react-native-cookie包,当用户退出应用程序时删除属于 Instagram 的 cookie。这很可能是问题所在。但是我不能从我的代码库中删除这个包,因为它是注销过程的必要部分。为了解决这个问题,我在 WebView 的“componentDidMount”生命周期方法中实现了以下代码,以从站点获取 cookie。但这对我的情况没有帮助。

Cookie.get( https://www.instagram.com);

这是一个关于stackoverflow 遇到完全相同问题的问题。然而,给出的解决方案是在 Obj-C 或 Swift 中,这两个我都不知道。我一直无法找到 React Native 的解决方案。

标签: react-nativecookieswebviewoauthinstagram

解决方案


关于 webapp 身份验证...问题与 instagram 平台有关。我发现只有当您的浏览器没有设置 instagram cookie“ig_cb”时才会出现问题。这是在您接受 instagram.com 上的 cookie 政策时设置的。解决方法是继续 Instagram 并接受 cookie 政策,然后返回您的社交身份验证并继续。

作为 instagram 登录过程的障碍......我想除了等待 instagram 错误修复之外没有明确的解决方案。


推荐阅读