0

php と cURL を介して Flurry イベント ログを認証してダウンロードしようとしています。Silkfireの投稿で途中まではできましたが、まだダウンロードに問題があります。認証されたと思いますが、ダウンロードすると、ファイルではなくエラー ページが返されるようです。私が試している最新のコードは次のとおりです。

$post = array(
  'loginEmail'        => 'email',
  'loginPassword'     => 'pw',
  //'rememberMeCheckbox' => 'true',
  //'__checkbox_rememberMeCheckbox' => 'true',
  'struts.token.name' => 'token',
);

//$ckfile = tempnam("/tmp", "FLURRYCOOKIE");

$ch = curl_init('https://dev.flurry.com/secure/login.do');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, null);
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

libxml_use_internal_errors(true);

$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTML(curl_exec($ch));

$xpath = new DOMXPath($dom);


$post['token'] = $xpath->query('//input[@name="token"]')->item(0)->getAttribute('value');


curl_setopt($ch, CURLOPT_URL, 'https://dev.flurry.com/secure/loginAction.do');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
//curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile );
//curl_setopt($ch, CURLOPT_COOKIESESSION, true );
//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$login = curl_exec($ch);

$log_url = 'https://dev.flurry.com/eventsLogCsv.do?projectID=12345&versionCut=versionsAll&intervalCut=30Days&childProjectId=0&stream=true&direction=1&offset=0';
$ch = curl_init();
//curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile );
curl_setopt($ch, CURLOPT_URL, $log_url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
//print_r($data);
$error = curl_error($ch);
curl_close ($ch);

$destination = "/tmp/flurry_event_log.csv";
$file = fopen($destination, "w");
fputs($file, $data);
fclose($file);

どんな助けでも大歓迎です。

更新: $data の応答の主な内容は次のとおりです。

    <div id="main">
    <!-- center -->
    <div id="centerColumn">
      <h1>&nbsp;</h1>
      <div class="fontSize" style="margin:50px;">
            <h2>Oops, an unexpected error has occurred.</h2>
            <br/><br/><br/>
            Please <a class="colorMediumBlue bold hover fontSize" href="/">go home</a> and try again.
            <br/><br/><br/>
            If you receive this same message more than once,
            please email <a class="colorMediumBlue bold hover fontSize" href="mailto:support@flurry.com">support@flurry.com</a> with details on how you arrived on this error page.
        <br/><br/>
        We apologize for this inconvenience and we will find a solution to this issue as soon as possible.
        <br/><br/>
        Sincerely,<br/>
        The Flurry Team
      </div>
  </div>
</div>
4

1 に答える 1

0

次の行コードを最初の curl 呼び出しに追加します。

curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");

次に、Cookie データを保存した後、次のように 2 回目の curl 呼び出しで使用します。

curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");

また、Cookie が保存されていることを確認し、/tmp/cookieFileName パスまたは必要なパスにアクセス許可の問題がないことを確認してください。

あなたのコードを編集しました。

<?php

$post = array(
    'loginEmail' => 'mertizci@xxxxx.com',
    'loginPassword' => 'xxxxxxx',
    //'rememberMeCheckbox' => 'true',
    //'__checkbox_rememberMeCheckbox' => 'true',
    'struts.token.name' => 'token',
);
$ch = curl_init('https://dev.flurry.com/secure/login.do');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, null);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

libxml_use_internal_errors(true);

$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTML(curl_exec($ch));

$xpath = new DOMXPath($dom);

$post['token'] = $xpath->query('//input[@name="token"]')->item(0)->getAttribute('value');

curl_setopt($ch, CURLOPT_URL, 'https://dev.flurry.com/secure/loginAction.do');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_exec($ch);

$log_url = 'https://dev.flurry.com/eventsLogCsv.do?projectID=12345&versionCut=versionsAll&intervalCut=30Days&childProjectId=0&stream=true&direction=1&offset=0';
curl_setopt($ch, CURLOPT_URL, $log_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
//print_r($data);
$error = curl_error($ch);
curl_close($ch);
echo $data;
?>
于 2016-03-03T20:50:23.357 に答える