我正在尝试使用php curl在reddit.com上提交链接帖子。我有访问权限的用户,但我无法在reddit上发布并获得错误代码403.以下是我尝试执行的示例代码:
$subreddit='funny';
$kind='link';
$postVals = sprintf("kind=%s&sr=%s&title=%s&r=%s",
$kind,
$subreddit,
urlencode('Test Post'),
$subreddit);
$postVals .= "&url=" . urlencode( 'http://seextra.com');
$urlSubmit = "http://www.reddit.com/api/v1/submit";
$ch = curl_init($urlSubmit);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 10
);
if (!empty($_SERVER['HTTP_USER_AGENT'])){
$options[CURLOPT_USERAGENT] = $_SERVER['HTTP_USER_AGENT'];
}
if ($postVals != null){
$options[CURLOPT_POSTFIELDS] = $postVals;
$options[CURLOPT_CUSTOMREQUEST] = "POST";
}
$headers = array("Authorization:bearer".$access_token , "User-Agent:".$_SERVER['HTTP_USER_AGENT']);
$options[CURLOPT_HEADER] = false;
$options[CURLINFO_HEADER_OUT] = false;
$options[CURLOPT_HTTPHEADER] = $headers;
$options[CURLOPT_USERPWD] = Reddit_Client_Id . ":" . Reddit_Client_secret;
// Reddit_Client_Id client id
// Reddit_Client_secret secret key
$options[CURLOPT_SSLVERSION] = 4;
$options[CURLOPT_SSL_VERIFYPEER] = false;
$options[CURLOPT_SSL_VERIFYHOST] = 2;
pr($options);
curl_setopt_array($ch, $options);
$apiResponse = curl_exec($ch);
$response = json_decode($apiResponse);
curl_close($ch);
print_r($response);
以下是来自reddit的回复:
stdClass Object
(
[error] => 403
)
你能否帮我解决这个问题。
谢谢, 萨钦