【发布时间】: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&code=fsdgsfgfbxf。
需要添加以下参数:page=instagram_auth&.
我尝试使用这段代码,但我陷入了重定向循环:
if (!empty($_GET['code'])) {
$this->instagram->set_code($_GET['code']);
header('Location:' . $config['redirect_uri'] . '&code=' . $_GET['code']);
die();
}
有谁知道我如何调用重定向但只重定向一次,并可能基于代码参数构建链接?
【问题讨论】: