Thursday, September 27, 2012

How to load Zotero into a webpage with 3 lines of PHP

It took me a little while to figure out how to load a formatted bibliography from Zotero into a Drupal page, so I thought I'd share what I came up with.

If publicly store your citations on zotero.org, you can also share these citations by means of Zotero's Read API.  The documentation to the Read API may initially look a little intimidating to non-programmers, but if you take a look at the examples provided by the documentation, you see that just by adding together clearly defined 'parts' you can easily create a link to some or all of your own Zotero library.

Here's a bibliography of mine formatted using APA: https://api.zotero.org/users/5110/collections/VDAA6PSK/items?format=bib&style=apa

Looking at the API, I think the only limitation that I think I need a workaround for that you can only generate COinS if you are generating an ATOM feed.

But I'm getting ahead myself. My goal is to embed this bibliography into a Drupal page. This way I - and others if we embed a shared bibliography - can use Zotero to handle citations and let Drupal handle the rest of the page that surrounds the bibliography.

And it can be done with three lines of PHP:




















And those lines loads the url of the bibliography into the body of the page:















If there is an even easier or better way to do this, please let me know.

9 comments:

Amanda French said...

Is that a dynamic bibliography? In other words, if you add to it, does it update in the Drupal page? I'm guessing yes . . .

Very cool. Thanks for posting it.

Mita said...

Yes - I've tested it out. It's not *instantaneous* but an update I made about an hour ago has already appeared.

Unknown said...

Hi there, great idea! Does the PHP text format need any special settings?

Mita said...

Hmm. I don't know if the PHP text format needs any special settings. This was just a proof of concept done within Drupal. Perhaps a test within WordPress would confirm whether it's necessary.

Anonymous said...

Hi!

interesting stuff, thanks!

Maybe you could also use JQuery's load function, than you would not need php (http://api.jquery.com/load/)

But I guess the inclusion is only possible if you set your Zotero library to public?
(I got a "forbidden" error when I tried to follow your example with a collection of mine..)

Anonymous said...

OK, please ignore my last comment ;-)

I found out about the use of API keys and that .load doesn't work across domains.. :-(

Anonymous said...

this is great, trying it out for drupal. However although the feed itself provides foreign characters correctly, e.g. https://api.zotero.org/users/19712/tags/-education/items?format=bib, something messes them up, I guess it is the php echo, so we get ć instead of ć etc.. Don't suppose you have any ideas?

Erik said...

Thanks, this is a really promising technique. Can you adapt it to get a slice of your Zotero collection? For instance, to return the results for a single source or a given author's works from within the collection? If so, this would be the solution to a lot of little problems for me.

Mita said...

Yes, you can slice you collection in a variety of ways: http://www.zotero.org/support/dev/server_api/v2/read_requests#get_requests