Getting started with Freebase and PHP

It seems some of the Freebase API examples are broken. Thanks to Bart for the heads up.

(Update Nov 07 – Freebase no longer requires an account for read access. So the cookie is probably unnecessary. )

Here are the most basic steps to getting started with Freebase PHP:

  1. Check your webserver runs PHP
  2. Download TestFreebasePHP.php to your webserver.
  3. View the PHP script through your server, you should see ‘Query failed’
  4. Check you are logged into your Freebase account.
  5. Get your metaweb-user cookie. (With Firefox: Preferences, Privacy, Show Cookies, search ‘Freebase’). It should look like this:
    metaweb-user="Z|a_aaaaaaaaaa|a_#1111a1a1111...snip...ZaaZZaZZ1aZ/ZZ"
  6. Test your cookie using this shell one-liner
  7. Edit TestFreebasePHP.php and replace the dummy cookie with your own.
  8. View the PHP script through your web server. If you see ‘Query succeeded’ then all is well.

I challenge you to come up with a smaller test script!

You can see the script running successfully on my server:

Test Freebase access using PHP

Loading: http://www.freebase.com/api/service/mqlread?q={"query":[{"id":"/type/int"}]}

Query succeeded
Response:

{
  "status": "200 OK",
  "query": {},
  "code": "/api/status/ok",
  "messages": [],
  "result": {
    "query": [
      {
        "id": "/type/int"
      }
    ]
  }
}
Advertisements

2 Responses to Getting started with Freebase and PHP

  1. […] Freebase API – cookie test Here is one line shell script to test your Freebase cookie. (Replace the dummy cookie with your own cookie): […]

  2. […] (Have you followed the steps in Getting started with Freebase and PHP?) […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: