0
私はこのコードをブラウザで実行するとうまくいきますが、それを実行するとcrontabはうまく動作しません。私は多くの時間を試して読んでいますが、この問題を解決することはできません。試してみたユーザーによって同様の問題が発生しましたが、これは役に立たなかった:this questionPHP CURLはブラウザ経由で動作しますが、Crontab経由では動作しませんか?
お勧めします!
おかげ
// curl settings and call to reddit
$ch = curl_init('https://www.reddit.com/api/v1/access_token');
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ':' . $clientSecret);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// curl response from reddit
$response_raw = curl_exec($ch);
$response = json_decode($response_raw);
curl_close($ch);
$accessToken = $response->access_token;
$accessTokenType = $response->token_type;
$username = variable_get('a_reddit_username');
$subredditName = variable_get('sub_reddit_name');
$subredditDisplayName = variable_get('sub_reddit_name');
$subredditPostTitle = $title;
$subredditUrl = $url;
// api call endpoint
$apiCallEndpoint = 'https://oauth.reddit.com/api/submit';
// post data: posting a link to a subreddit
$postData = array(
'url' => $subredditUrl,
'title' => $subredditPostTitle,
'sr' => $subredditName,
'kind' => 'link'
);
// curl settings and call to post to the subreddit
$ch = curl_init($apiCallEndpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $subredditDisplayName . ' by /u/' . $username . ' (Phapper 1.0)');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: " . $accessTokenType . " " . $accessToken));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// curl response from our post call
$response_raw = curl_exec($ch);
$response = json_decode($response_raw);
curl_close($ch);
あなたはcrontabの中で、あなたのメールアドレスを追加することにより、どのようなエラーの原因を確認してください。 –
偽のユーザーエージェントを設定してみてください:http://stackoverflow.com/questions/2440729/php-curl-how-can-i-emulate-a-get-request-exactly-like-web-browser – MilanG
ありがとうcurl_setopt($ ch、CURLOPT_USERAGENT、$ subredditDisplayName。 '/ u /'。$ username。 '(Phapper 1.0)')のようなユーザエージェントを設定しています。どのようなエラーをテストするための他の方法はありますか? – jas