2014-02-23 34 views
0

我对入门文档的游离碱,在那里我会用我的API密钥在这个例子困惑:PHP - 我在哪里使用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文件,该键去在这个文件中?在网址?

+0

你想要做什么或者它是不是你想要的? – qooplmao

+0

这是本页面的一个示例:https://developers.google.com/freebase/v1/topic-overview,它应该“检索Freebase主题并显示主题名称” – user2219915

+0

如果我的api密钥是blahblahblah,并且我把php页面放在example.com/freebase.php,我尝试创建url http:http://example.com/freebase.php?key=blahblahblah,但我没有' – user2219915

回答

2

似乎你的钥匙应该是$freebase_api_key。因此,只要给它分配你有PARAMS线以上键值:

$freebase_api_key = 'blahblahblah'; 

该脚本将自动调用你和回声(一些)输出。

相关问题