私は Facebook グループの管理者 (マネージャーの役割) です。id
アプリを作成し、そのとを保存しましたsecret
。
アプリで Facebook グループのフィードに何かを投稿できるようにしたいと考えています。しかし、投稿しようとすると、publish_stream および offline_access スコープで190 Invalid OAuth access token signature
正常に取得できたにもかかわらず、エラーが発生します。access_token
NはNNNNNNNNNNNNNNN|XXXXXXXXXXXXXXXXXXXXXXXXXXX
数字 (15)、X は文字または数字 (27) です。
これを達成するには、さらに何をすべきですか?私が使用しているコードは次のとおりです。
public static function postToFB($message, $image, $link) {
//Get App Token
$token = self::getFacebookToken();
// Create FB Object Instance
$facebook = new Facebook(array(
'appId' => self::fb_appid,
'secret' => self::fb_secret,
'cookie' => true
));
//$token = $facebook->getAccessToken();
//Try to Publish on wall or catch the Facebook exception
try {
$attachment = array('access_token' => $token,
'message' => $message,
'picture' => $image,
'link' => $link,
//'name' => '',
//'caption' => '',
'description' => 'More...',
//'actions' => array(array('name' => 'Action Text', 'link' => 'http://apps.facebook.com/xxxxxx/'))
);
$result = $facebook->api('/'.self::fb_groupid.'/feed/', 'post', $attachment);
} catch (FacebookApiException $e) { //If the post is not published, print error details
echo '<pre>';
print_r($e);
echo '</pre>';
}
}
トークンを返すコード
//Function to Get Access Token
public static function getFacebookToken($appid = self::fb_appid, $appsecret = self::fb_secret) {
$args = array(
'grant_type' => 'client_credentials',
'client_id' => $appid,
'client_secret' => $appsecret,
'redirect_uri' => 'https://www.facebook.com/connect/login_success.html',
'scope' => 'publish_stream,offline_access'
);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
try {
$data = curl_exec($ch);
} catch (Exception $exc) {
error_log($exc->getMessage());
}
return json_encode($data);
}
投稿コードのコメントを外す$token = $facebook->getAccessToken();
と、さらに別のエラーが発生します(#200) The user hasn't authorized the application to perform this action
。
developers.facebook.com/tools/explorer/を使用して取得したトークン は別の形式で、はるかに長く、グループ ページ フィードに投稿できます。
Graph API Explorerからコピー/貼り付けせずに投稿するにはどうすればよいですか? また、ユーザーとして投稿する代わりにグループとして投稿するにはどうすればよいですか?
ありがとう。