Freebase API调用在浏览器中工作,但失败与curl [英] Freebase API call works in browser but fails with curl

查看:207
本文介绍了Freebase API调用在浏览器中工作,但失败与curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Freebase API接收数据。我手动构建了一个工作的API调用,它在我的浏览器中给了我一个有效的JSON响应。所以我写了一个PHP函数,应该这样做:

I'm trying to receive data from the Freebase API. I manually built a working API call which gave me a valid JSON response in my browser. So I wrote a PHP Function which should do exactly that:

$service_url = 'https://www.googleapis.com/freebase/v1/search';
$params = array(
           'filter' => '(all name:"Avatar")',
           'lang' => 'en',
           'type' => 'film/film',
           'key' => Configure::read('Api.Key')
         );
$url = $service_url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);

我得到的响应是 NULL 如果我使用构建的网址并将其输入到我的Chrome REST插件或直接在浏览器中查看,我会得到有效的响应。如果url有效,为什么我的curl函数失败?

The response I get is NULL, but if I take the built URL and enter it into my Chrome REST Plugin or view it directly in the browser, I get a valid response. If the url is valid, why would my curl function fail?

推荐答案

>

For me by adding the below line worked.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

这篇关于Freebase API调用在浏览器中工作,但失败与curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆