我一直在将应用程序从旧的Bing API移植到新的应用程序。看到了几篇关于PHP在PHP中如何工作的文章,我得到了关于它的认证问题。新的Bing API在PHP中不支持的身份验证
这是由URL返回的错误:
Warning: file_get_contents(https://api.datamarket.azure.com/Bing/Search/Image?$format=json&Query=%27%27) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 The authorization type you provided is not supported. Only Basic and OAuth are supported in /home/krem81/public_html/classes/class.BingSearch.php on line 178
而反过来,这是我使用与API交互的功能:
$accountKey = $this->Appid;
$ServiceRootURL = "https://api.datamarket.azure.com/Bing/Search/";
$WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';
$context = stream_context_create(array(
'http' => array(
'request_fulluri' => true,
'header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
)
));
$request = $WebSearchURL . urlencode('\'' . $_POST["searchText"] . '\'');
echo($request);
$this->response = file_get_contents($request, 0, $context);
$this->results = json_decode($this->response);
由于尝试这种我现在也试过
$accountKey = $this->Appid;
$ServiceRootURL = "https://api.datamarket.azure.com/Bing/Search/";
$WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';
$request = $WebSearchURL . urlencode('\'' . $this->keyword . '\'');
echo($request);
$process = curl_init($request);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD, $accountKey . ":" . $accountKey);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$this->response = curl_exec($process);
var_dump($this->response);
$this->results = json_decode($this->response);
var_dump($this->results);
有没有人有什么想法可以触发au认证失败?
可能重复(http://stackoverflow.com/questions/10844463/bing-search-api-and-azure) – ManseUK 2012-08-07 10:16:14
不幸的线程没有帮助,尝试了所有的解决方案,他们都没有让我到任何地方 – 2012-08-07 10:17:50
你检查了标题以确保密钥实际存在吗? – ManseUK 2012-08-07 10:20:41