0

I am confused by the getting started docs for Freebase, where would I use my API key in this example:

<!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'];
?>

If I create this PHP file on my server, does the key go in this file? In the url?

user2219915
  • 289
  • 3
  • 7
  • 19
  • What is it that you want to do or what is it that is not working how you would like it to? – qooplmao Feb 23 '14 at 05:52
  • This is an example from this page: https://developers.google.com/freebase/v1/topic-overview and it is supposed to "retrieve a Freebase topic and display the topic name" – user2219915 Feb 23 '14 at 05:52
  • if my api key was blahblahblah and I put the php page at example.com/freebase.php, I tried creating the url http: http://example.com/freebase.php?key=blahblahblah but I got nothin' – user2219915 Feb 23 '14 at 05:55
  • The API is at `https://www.googleapis.com/freebase/v1/topic` so you would need to use `https://www.googleapis.com/freebase/v1/topic?key=blahblahblah`. – qooplmao Feb 23 '14 at 05:58

1 Answers1

2

Seems like your key should be $freebase_api_key. So just assign it the key value you have above the params line:

$freebase_api_key = 'blahblahblah';

The script will make an auto call for you and echo (some) output.

Shomz
  • 37,421
  • 4
  • 57
  • 85