我试图联系并使用这个人在这里解释的http://qnimate.com/wordpress-frontend-facebook-login/所以我可以允许使用Facebook帐户登录。我按照添加按钮的说明,我将php文件上传到它的路径,并使用在那里提供的链接制作按钮。 我制作了Facebook应用程序,我在inc / facebookoauth.php中添加了应用程序ID和密钥 这是代码:
function facebook_oauth_redirect()
{
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require_once("../wp-load.php");
//construct URL and redirect
$app_id = get_option("facebook_app_id");
$redirect_url = get_site_url() . "/wp-admin/admin-ajax.php?action=facebook_oauth_callback";
$permission = "email,name";
$final_url = "https://www.facebook.com/dialog/oauth?client_id=" . urlencode($app_id) . "&redirect_uri=" . urlencode($redirect_url) . "&scope=" . $permission;
header("Location: " . $final_url);
die();
}
add_action("wp_ajax_facebook_oauth_redirect", "facebook_oauth_redirect");
add_action("wp_ajax_nopriv_facebook_oauth_redirect", "facebook_oauth_redirect");
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
function facebook_oauth_callback()
{
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require_once("../wp-load.php");
if(isset($_GET["code"]))
{
$token_and_expire = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=" . get_option("facebook_app_id") . "&redirect_uri=". get_site_url() . "/wp-admin/admin-ajax.php?action=facebook_oauth_callback" . "&client_secret=" . get_option("facebook_app_secret") . "&code=" . $_GET["code"]);
parse_str($token_and_expire, $_token_and_expire_array);
if(isset($_token_and_expire_array["access_token"]))
{
$access_token = $_token_and_expire_array["access_token"];
$user_information = file_get_contents("https://graph.facebook.com/me?access_token=" . $access_token . "&fields=email,name");
$user_information_array = json_decode($user_information, true);
$email = $user_information_array["email"];
$name = $user_information_array["name"];
if(username_exists($name))
{
$user_id = username_exists($name);
wp_set_auth_cookie($user_id);
update_user_meta($user_id, "facebook_access_token", $access_token);
header('Location: ' . get_site_url());
}
else
{
//create a new account and then login
wp_create_user($name, generateRandomString(), $email);
$user_id = username_exists($name);
wp_set_auth_cookie($user_id);
update_user_meta($user_id, "facebook_access_token", $access_token);
header('Location: ' . get_site_url());
}
}
else
{
header("Location: " . get_site_url());
}
}
else
{
header("Location: " . get_site_url());
}
die();
}
add_action("wp_ajax_facebook_oauth_callback", "facebook_oauth_callback");
add_action("wp_ajax_nopriv_facebook_oauth_callback", "facebook_oauth_callback");
所以你可以看到“facebook_app_secret”和“facebook_app_id”,我在那里添加了两个代码。因此,当我尝试按下按钮时,它会返回此错误,说参数app_id是必需的。 你认为这是怎么回事?