2015-09-15 68 views
6

我試圖使捲曲GET刮Facebook的Open Graph的對象:捲曲獲取與包含GET URL的參數請求

GET https://graph.facebook.com/?id=OBJECT_URL &刮=真&方法=張貼

在我的情況下,OBJECT_URL包含GET參數:

https://www.example.com/og.php?a=b&c=d

出於這個原因,我不能公頃它已經在的file_get_contents GET參數()或CURLOPT_URL,因爲它會變成這樣的事情:

https://graph.facebook.com/?id=https://www.example.com/og.php?a=b&c=d &刮=真&方法=張貼

有沒有辦法將它傳遞作爲GET參數的方式類似於CURLOPT_POSTFIELDS?

回答

14

你需要逃避你的參數,該http_build_query功能將是有益的:

$query = http_build_query([ 
'id' => 'http://foo?a=1&b=2', 
'scrape' => true, 
'method' => 'post' 
]); 

$url = "https://graph.facebook.com/?".$query; 

var_dump($url); 

這將輸出:

https://graph.facebook.com/?id=http%3A%2F%2Ffoo%3Fa%3D1%26b%3D2&scrape=1&method=post 
+0

我學到新的東西,謝謝:) –