2013-03-04 108 views
4

我收到信息给Facebook使用的file_get_contents()如何使用卷曲在Facebook的图形API请求

但有时我接收到错误图形API。

我发现必须使用cURL而不是file_get_contents()。

问题是,我不知道如何使用cURL与我需要通过的URL。

如果我转换

file_get_contents($graph_url); 

成卷曲,会是怎样的代码?

这里是$ graph_url

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

内容阅读如何提出请求卷曲文档。 – 2013-03-04 14:17:38

回答

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

谢谢@MaulikVora – 2013-03-04 14:18:05

+0

如果我的$ graph_url ='https://graph.facebook.com/'如何。 'FQL Q = SELECT + src_big + FROM +照片+ WHERE + OBJECT_ID =' $ photo_id。 '&access_token ='。 $的access_token;对于fql, – 2013-03-06 05:17:35

+0

,'file_get_contents'更合适。我在fql中使用了这个函数。 – 2013-03-06 09:14:37