所以我從 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 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();
}
有誰知道我如何呼叫重定向但只重定向一次并可能基于代碼引數構建鏈接?
uj5u.com熱心網友回復:
這是我得到的 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
注意,我只是在最后添加了引數。這只需要您將&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();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/395524.html
