Facebook-ユーザーの壁にストーリーを公開します
-
25-10-2019 - |
質問
私はFacebook-PHP-SDKを使用していますが、私の要件はユーザーの壁にストーリーを投稿することです。私のアプリは、サインアップ/ログイン時にユーザーに「publish_stream」許可を要求します。ユーザーが許可を許可してログインした後、どういうわけか、私はFacebook Wallにアプリでユーザーが作成した新しいコメントを公開することができません。これは私が得るエラーです:
Invalid OAuth access token signature
これが私がすることです:
$facebook = new Facebook(array(
'appId' => "$fb_app_id",
'secret' => "$fb_secret",
'cookie' => true
));
try {
$fb_user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$facebook->api("/me/feed", 'post', array(
'access_token' => $access_token,
'message' => 'I love SO',
'link' => 'http://mydomain.com',
'picture' => 'http://thinkdiff.net/ithinkdiff.png',
'name' => 'iOS Apps & Games',
'description'=> 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'
)
);
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
}
あなたの考えを共有してください
解決
次のコードを使用してFacebookウォールに投稿できます。適切な引数で関数を呼び出すだけです
これを試して 、
<?php
function doWallPost($postName='',$postMessage='',$postLink='',$postCaption='',$postDescription='')
{
$FB_APP_ID='xxxxxxxxxxxxxxxxxxxxxxxx';
$FB_APP_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$APP_RETURN_URL=((substr($_SERVER['SERVER_PROTOCOL'],0,4)=="HTTP")?"http://":"https://").$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$code = $_REQUEST["code"];
if(empty($code))
{
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$FB_APP_ID."&redirect_uri=".$APP_RETURN_URL."&scope=publish_stream";
header("Location:$dialog_url");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$FB_APP_ID."&redirect_uri=".urlencode($APP_RETURN_URL)."&client_secret=".$FB_APP_SECRET."&code=".$code;
$access_token = file_get_contents($token_url);
$param1=explode("&",$access_token);
$param2=explode("=",$param1[0]);
$FB_ACCESS_TOKEN=$param2[1];
$url = "https://graph.facebook.com/me/feed";
$attachment = array( 'access_token' => $FB_ACCESS_TOKEN,
'name' => $postName,
'link' => $postLink,
'description' => $postDescription,
'message' => $postMessage,
'caption' => $postCaption,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result=curl_exec($ch);
header('Content-type:text/html');
curl_close($ch);
return $result
}
?>
他のヒント
アプリを再度インストールします https://developers.facebook.com/tools/explorer/アプリを選択し、[アクセストークンの取得]をクリックしてください。まだ問題が発生している場合は、開発者ダッシュボードに移動しますhttps://developers.facebook.com/apps設定の編集]をクリックして、サイトURL:フィールドで正しいURLを設定します。
所属していません StackOverflow