5

file_get_contents() を使用して Facebook グラフ API に情報を取得しています

しかし、時々エラーが発生します。

file_get_contents() の代わりに cURL を使用する必要があることがわかりました。

問題は、渡す必要がある URL で cURL を使用する方法がわからないことです。

私が変換した場合

file_get_contents($graph_url);

cURL に変換すると、コードはどうなりますか?

ここに $graph_url のコンテンツがあります

$graph_url= "https://graph.facebook.com/me/photos?"
  . "url=" . urlencode($photo_url)
  . "&message=" . urlencode('')
  . "&method=POST"
  . "&access_token=" .$access_token;
4

1 に答える 1

17
    $graph_url= "https://graph.facebook.com/me/photos";
  $postData = "url=" . urlencode($photo_url)
  . "&message=" . urlencode('')
  . "&access_token=" .$access_token;
                
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $graph_url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        $output = curl_exec($ch);

        curl_close($ch);
于 2013-03-04T14:04:57.247 に答える