2017-04-24 4 views
0

Lorsque j'exécute ce code via le navigateur, il fonctionne très bien mais quand nous l'exécutons, alors cela ne fonctionne pas. J'essaie et je lis de beaucoup de temps mais je ne peux pas résoudre ce problème. Il y avait un problème similaire rencontré par certains utilisateurs que j'ai essayé, mais cela n'a pas aidé: this questionPHP CURL fonctionne via un navigateur mais pas via Crontab?

S'il vous plaît suggérer!

Merci

// 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); 
+0

Vous vérifiez quelle cause d'erreur en ajoutant votre adresse e-mail dans crontab. –

+0

Essayez de définir l'agent utilisateur faux, comme: http://stackoverflow.com/questions/2440729/php-curl-how-can-i-emulate-a-get-request-exactly-like-a-web-browser – MilanG

+0

Merci mais j'ai défini l'agent utilisateur comme curl_setopt ($ ch, CURLOPT_USERAGENT, $ subredditDisplayName. 'par/u /'. $ nom d'utilisateur. '(Phapper 1.0)'); Y at-il un autre moyen de tester quelle erreur il Thorugh !! – jas

Répondre

0

utilisation cron job comme ci-dessous.

* 05 * * * wget http://www.YourUrl.com/test.php -O /yourPath/errorLog.txt 

code "/yourPath/errorLog.txt" pour errro Lod pendant le chargement de ..