how to use cURL in facebook graph api request

2019-02-07 08:47发布

I am getting the information to facebook graph api using file_get_contents()

but sometimes I am receiving an error.

I found out that cURL must be used instead of file_get_contents().

The problem is, I don't know how to use cURL with the URL that I need to pass.

if I converted

file_get_contents($graph_url);

into cURL, what will be the code?

here is the content of $graph_url

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

1条回答
爷的心禁止访问
2楼-- · 2019-02-07 09:27
    $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);
查看更多
登录 后发表回答