私はFacebook Graph APIに接続し、最終的にFacebookページに投稿するために使用されるWordPressプラグインを構築しています。私は自分のドキュメントに従っているし、 "Facebookでログイン"をクリックすると、500サーバーのエラーが発生しています。コード= "トークン"がURLに戻ってきますが、サーバーのエラーは500です。Facebook Graph API PHP 5.0 - 500 getLoginUrl()のエラー
私が実行しています。..
- PHP:私はFB-callback.phpファイルからすべてを取るとちょうどエコーそれは作業」をした場合5.4
- のmbstringが
を有効になっていますページに表示され、何も壊れませんが、私はちょうどその下に接続するFacebookを持っているときに壊れて...と私は500のエラーを取得します。
$fb = new Facebook\Facebook([
'app_id' => 'my-secret',
'app_secret' => 'my-id',
'default_graph_version' => 'v2.8',
]);
以下はコードの残りの部分です。これはWordPress Pluginであり、私が開発している最初のものなので、組織内で少し混乱していると確信しています。あなたは、FB-の先頭にsession_start()
を呼び出す必要が
<?php
session_start();
$fb = new Facebook\Facebook([
'app_id' => 'my-id',
'app_secret' => 'my-secret',
'default_graph_version' => 'v2.8',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'manage_pages', 'publish_pages', 'user_posts']; // Optional permissions
$loginUrl = $helper->getLoginUrl('http://p11socialplugin.p11.com/wp-content/plugins/p11-social/fb-callback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>
ここで全体のFB-callback.php
<?php
$fb = new Facebook\Facebook([
'app_id' => 'my-app-id ', // Replace {app-id} with your app id
'app_secret' => 'my-app-secret',
'default_graph_version' => 'v2.8',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
// Logged in
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);
// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId({app-id}); // Replace {app-id} with your app id
// If you know the user ID this access token belongs to, you can validate it here
//$tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();
if (! $accessToken->isLongLived()) {
// Exchanges a short-lived access token for a long-lived one
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
exit;
}
echo '<h3>Long-lived</h3>';
var_dump($accessToken->getValue());
}
$_SESSION['fb_access_token'] = (string) $accessToken;
// User is logged in with a long-lived access token.
// You can redirect them to a members-only page.
//header('Location: https://p11socialplugin.p11.com/wp-admin');
?>
エラーログ
ある[30-Jan-2017 22:03:28 UTC] PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Users/garrett/Development/wp-playground/wp-content/themes/twentyseventeen/header.php:16) in /Users/garrett/Development/wp-playground/wp-content/themes/twentyseventeen/facebook.php on line 2
[30-Jan-2017 22:03:28 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/garrett/Development/wp-playground/wp-content/themes/twentyseventeen/header.php:16) in /Users/garrett/Development/wp-playground/wp-content/themes/twentyseventeen/facebook.php on line 2
[30-Jan-2017 22:03:58 UTC] PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Users/garrett/Development/wp-playground/wp-admin/includes/template.php:1995) in /Users/garrett/Development/wp-playground/wp-content/plugins/p11-social/class.p11-social.php on line 103
[30-Jan-2017 22:03:58 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/garrett/Development/wp-playground/wp-admin/includes/template.php:1995) in /Users/garrett/Development/wp-playground/wp-content/plugins/p11-social/class.p11-social.php on line 103
[30-Jan-2017 22:04:08 UTC] PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Users/garrett/Development/wp-playground/wp-admin/includes/template.php:1995) in /Users/garrett/Development/wp-playground/wp-content/plugins/p11-social/class.p11-social.php on line 103
[30-Jan-2017 22:04:08 UTC] PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/garrett/Development/wp-playground/wp-admin/includes/template.php:1995) in /Users/garrett/Development/wp-playground/wp-content/plugins/p11-social/class.p11-social.php on line 103
サーバーエラーログを確認し、PHPエラーログを確認します。 (まだ起動していなければ、後者を有効にしてください。) – CBroe
@CBroeはエラーログを追加しました。見出しはヘッダーを送信することと関係があります。これを回避する方法がわかりません。初期設定ページでセッション開始を呼び出します。 –