フォーラムランナーAPIを使用して、フォーラムのユーザーにメッセージを外部に送信しようとして問題が発生しました。
私はこのコードで正常にログインすることができました:
function login($username, $password){
$postdata = "cmd=login&username=".$username."&password=".$password;
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://forums.<<<website>>>.org/forumrunner/request.php', false, $context);
$resultantArray = json_decode($result, true);
if($resultantArray['success'] == true){
$this->loginresult=$resultantArray;
return true;
} else {
$this->loginresult=false;
return false;
}
}
結果:
array(5) { ["success"]=> bool(true) ["data"]=> array(6) { ["username"]=> string(8) "<<<Username>>>" ["authenticated"]=> bool(true) ["v"]=> string(5) "1.1.1" ["p"]=> string(5) "xen10" ["requires_authentication"]=> bool(false) ["reg"]=> bool(true) } ["ads"]=> int(0) ["pm_notices"]=> int(0) ["sub_notices"]=> int(0) } string(4395) "
これで機能し、ログイン成功メッセージが返されますが、新しい会話を開始するためのこのコードは機能していません(認証に失敗します)。
function sendPM($recipients, $title, $message) {
$postdata = "cmd=start_conversation&recipients=".$recipients."&title=".$title."&message=".$message."&d=1";
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://forums.<<<website>>>.org/forumrunner/request.php', false, $context);
$resultantArray = json_decode($result, true);
if($resultantArray['success'] == true){
$this->pmresult=$resultantArray;
return true;
} else {
$this->pmresult=$result;
return false;
}
}
そしてエラー(重要な部分):
{"success":false,"message":"You do not have permission to view this page or perform this action."}
ある種のセキュリティトークンを一緒に渡す必要があると思いますが、どこで入手できるかわかりません。