【问题标题】:Instagram Authorization Page Redirect is Endlessly Reloading My Web PageInstagram 授权页面重定向正在无休止地重新加载我的网页
【发布时间】:2021-12-27 23:14:28
【问题描述】:

所以我有来自 Instagram 基本显示 API 的以下方法:

public function get_authorization_window(): string
    {
        $auth_url = $this->instagram->get_api_oauth_url() . '?' . http_build_query([
            'client_id' => $this->instagram->get_client_id(),
            'redirect_uri' => admin_url('options-general.php?page=instagram_auth'),
            'scope' => 'user_profile,user_media',
            'response_type' => 'code',
            'state' => admin_url('options-general.php?page=instagram_auth'),
        ]);

        return '<a class="button button-primary" href="' . $auth_url . '">Please click here to authorize Instagram for this site</a></p>';
    }

现在,当它构建 URL 时,它会返回一个 code=dsgzdfsgzsfsbfb 参数。

这是我返回的 URL:https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf。

这里是我想要重定向的地方:https://test.com.local/wp-admin/options-general.php?page=instagram_auth&amp;code=fsdgsfgfbxf。

需要添加以下参数:page=instagram_auth&amp;.

我尝试使用这段代码,但我陷入了重定向循环:

if (!empty($_GET['code'])) {
     $this->instagram->set_code($_GET['code']);
     header('Location:' . $config['redirect_uri'] . '&code=' . $_GET['code']);
     die();
}

有谁知道我如何调用重定向但只重定向一次,并可能基于代码参数构建链接?

【问题讨论】:

    标签: php wordpress instagram


    【解决方案1】:

    这是我返回的 URL:

    https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf.

    这里是我想要重定向的地方:

    https://test.com.local/wp-admin/options-general.php?page=instagram_auth&code=fsdgsfgfbxf。

    顺序并不重要。如果您只有第一个字符串,则以下 URL 应该就足够了:

    https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf&page=instagram_auth

    注意,我只是在最后添加参数。这只需要您将 &amp;page=instagram_auth 参数附加到您已有的字符串中。

    无论GET 参数的顺序如何,页面都应该可以正常工作。

    很难说到底发生了什么,但也许可以试试?

    if (!empty($_GET['code']) && $_GET['done'] != "1")) {
         $this->instagram->set_code($_GET['code']);
         header('Location:' . $config['redirect_uri'] . '&done=1&code=' . $_GET['code']);
         die();
    }
    

    【讨论】:

    • 这很高兴知道!我不知道这一点,是否还有一种安全的方法可以将 URL 重定向到 &page=instagram_auth 参数? Instagram 删除了所有查询字符串,我需要在最后添加它,但我陷入了重定向循环,因为 code=vdvzsvs 留在网址中。
    • @Glider:嗯,我不是 100% 清楚你的问题。但是您希望它重定向一次,然后不再重定向?这行得通吗?将header('Location:' . $config['redirect_uri'] . '&amp;code=' . $_GET['code']); 更改为header('Location:' . $config['redirect_uri']);?
    • 我刚刚添加了一些可能解决您的问题的代码,让我知道它是否有效!
    • 有效!非常感谢!我刚刚接受了答案。
    猜你喜欢
    • 2015-01-26
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2016-05-21
    • 2011-11-19
    相关资源
    最近更新 更多