【发布时间】:2014-02-23 05:43:53
【问题描述】:
我对 Freebase 的入门文档感到困惑,在这个示例中我应该在哪里使用我的 API 密钥:
<!DOCTYPE html>
<html>
<body>
<?php
include('.freebase-api-key');
$service_url = 'https://www.googleapis.com/freebase/v1/topic';
$topic_id = '/en/bob_dylan';
$params = array('key'=>$freebase_api_key);
$url = $service_url . $topic_id . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$topic = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $topic['property']['/type/object/name']['values'][0]['value'];
?>
如果我在我的服务器上创建这个 PHP 文件,密钥会在这个文件中吗?在网址中?
【问题讨论】:
-
您想要做什么,或者有什么不符合您的要求?
-
这是来自此页面的示例:developers.google.com/freebase/v1/topic-overview,它应该“检索 Freebase 主题并显示主题名称”
-
如果我的 api 密钥是 blahblahblah 并且我将 php 页面放在 example.com/freebase.php,我尝试创建 url http:example.com/freebase.php?key=blahblahblah 但我一无所获
-
API 位于
https://www.googleapis.com/freebase/v1/topic,因此您需要使用https://www.googleapis.com/freebase/v1/topic?key=blahblahblah。