2016-08-01 183 views
1

當我試圖訪問API MOZ使用以下代碼Mozaps API請求被Incapsula阻止?

$accessID = 'mozscape-key'; 
$secretKey = 'secert key'; 
// Set your expires times for several minutes into the future. 
// An expires time excessively far in the future will not be honored by the Mozscape API. 
$expires = time() + 300; 
// Put each parameter on a new line. 
$stringToSign = $accessID."\n".$expires; 
// Get the "raw" or binary output of the hmac hash. 
$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true); 
// Base64-encode it and then url-encode that. 
$urlSafeSignature = urlencode(base64_encode($binarySignature)); 
// Specify the URL that you want link metrics for. 
$objectURL = "www.seomoz.org"; 
// Add up all the bit flags you want returned. 
// Learn more here: https://moz.com/help/guides/moz-api/mozscape/api-reference/url-metrics 
$cols = "103079215108"; 
// Put it all together and you get your request URL. 
// This example uses the Mozscape URL Metrics API. 
$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/".urlencode($objectURL)."?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature; 
echo $requestUrl; 
die; 
// Use Curl to send off your request. 
$options = array(
    CURLOPT_RETURNTRANSFER => true 
    ); 
$ch = curl_init($requestUrl); 
curl_setopt_array($ch, $options); 
$content = curl_exec($ch); 
curl_close($ch); 
$f = fopen('tte.txt','a'); 
fwrite($f,$content); 
fclose($f); 
print_r($content); 

的出它返回低於

<html style="height:100%"> 
<head> 
    <meta content="NOINDEX, NOFOLLOW" name="ROBOTS"> 
    <meta content="telephone=no" name="format-detection"> 
    <meta content="initial-scale=1.0" name="viewport"> 
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> 
    <title></title> 
</head> 
<body style="margin:0px;height:100%"> 
    <iframe frameborder="0" height="100%" marginheight="0px" marginwidth="0px" 
    src="/_Incapsula_Resource?CWUDNSAI=9&xinfo=10-113037580-0%200NNN%20RT(1470041335360%200)%20q(0%20-1%20-1%20-1)%20r(0%20-1)%20B12(8,811001,0)%20U5&incident_id=220010400174850153-812164000562037002&edet=12&cinfo=08000000" 
    width="100%">Request unsuccessful. Incapsula incident ID: 
    220010400174850153-812164000562037002</iframe> 
    <meta content="NOINDEX, NOFOLLOW" name="ROBOTS"> 
    <meta content="telephone=no" name="format-detection"> 
    <meta content="initial-scale=1.0" name="viewport"> 
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> 
    <iframe frameborder="0" height="100%" marginheight="0px" marginwidth="0px" 
    src="/_Incapsula_Resource?CWUDNSAI=9&xinfo=6-31536099-0%200NNN%20RT(1470041496215%200)%20q(0%20-1%20-1%20-1)%20r(0%20-1)%20B12(8,811001,0)%20U5&incident_id=220010400174850153-224923142338658566&edet=12&cinfo=08000000" 
    width="100%">Request unsuccessful. Incapsula incident ID: 
    220010400174850153-224923142338658566</iframe> 
</body> 
</html> 

好像incapsula被處理請求作爲機器人。任何人都可以請幫助我如何修復它。

+0

更好的掩蓋祕密密鑰和accessID,如果它是私人的 –

+0

我做過之前,但後來又取代了代碼。現在修復。謝謝 – deepsingh

+0

Basiaclly它說有一個請求的問題,「機器人」只適用於元數據,它不認爲你是一個機器人。我不熟悉php,但請求參數應該是$ accessID或$ accessID(沒有點),以及爲什麼要在URL之後添加objectURL? –

回答

0

如果你說你正在使用$ requestUrl到一個GET(在瀏覽器中)它工作正常,請嘗試結合你的選項數組。

它應該是這樣的:

$ch = curl_init(); 
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => $requestUrl, 
    CURLOPT_USERAGENT => 'Maybe You Need Agent?' 
)); 

備註劑(網絡獲取):

捲曲是一個龐然大物,而且有很多很多可能性。有些網站可能只向某些用戶代理提供頁面,並且在使用API​​時,某些 可能會要求您發送specfici用戶代理,這可能是 意識到的問題。

另外值得一檢查 - 你Incapsula有failture的ID - 220010400174850153-224923142338658566

您可以檢查日誌,看看還有什麼?