How to specify an API key

78 views
Skip to first unread message

Richard Lent

unread,
Nov 22, 2011, 3:56:26 PM11/22/11
to zotero-dev
I am using the ASIHTTPRequest library in an attempt to access the
Zotero API via GET, POST, etc.

I keep getting the error,

"You must specify a key to access the Zotero API."

I have tried what I think are all possible ways to specify my API key
as described in the API documentation, to no avail.

Are there any explicit code examples available?

Thanks,

Rich Lent

Rönkkö Mikko

unread,
Nov 23, 2011, 1:34:37 AM11/23/11
to <zotero-dev@googlegroups.com>

On Nov 22, 2011, at 22:56, Richard Lent wrote:

> I am using the ASIHTTPRequest library in an attempt to access the
> Zotero API via GET, POST, etc.
>
> I keep getting the error,
>
> "You must specify a key to access the Zotero API."

You must add a parameter 'key' containing a valid API key to the request. See http://www.zotero.org/support/dev/server_api/read_api#authentication

>
> I have tried what I think are all possible ways to specify my API key
> as described in the API documentation, to no avail.
>
> Are there any explicit code examples available?

Yes. The authentication document to which I link above provides a link to creating keys manually and a link to php code that shows how keys are generated with OAuth. If you want an example using Objective C you can take a look at ZotPad (https://github.com/mronkko/ZotPad).

What are you developping? I am fairly sure that a better option than using ASIHTTPRequest woudl be to just initialize NSXMLParser with an URL. This will result in less code and I also believe that it allows you to start parsing the response as it arrives instead of waiting for the data transfer to complete.

Here is an example from ZotPad

-(NSArray*) retrieveLibrariesFromServer{

//Retrieve all libraries from the server

NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.zotero.org/users/%@/groups?key=%@",_userID,_oauthkey]];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:fileURL];

ZPServerResponseXMLParser* parserDelegate = [[ZPServerResponseXMLParser alloc] init];

[parser setDelegate: parserDelegate];
[parser parse];

return [parserDelegate results];

}


If you are developing for iPhone/iPad, I would like to hear more about your project. Also if you plan to release your code as open source it might make sense to merge your project with ZotPad or the other way around to avoid duplicate work.

MIkko


>
> Thanks,
>
> Rich Lent
>
> --
> You received this message because you are subscribed to the Google Groups "zotero-dev" group.
> To post to this group, send email to zoter...@googlegroups.com.
> To unsubscribe from this group, send email to zotero-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/zotero-dev?hl=en.
>

Richard Lent

unread,
Nov 23, 2011, 11:46:16 AM11/23/11
to zotero-dev
Thanks for your reply Mikko. At this point I'm just trying to learn
the Zotero API to see what's possible in an iOS app. I'm ok with the
read API but am having trouble with how to specify a key for the write
API, so that items could be added and edited to an online library.

On Nov 23, 1:34 am, Rönkkö Mikko <mikko.ron...@aalto.fi> wrote:
> On Nov 22, 2011, at 22:56, Richard Lent wrote:
>
> > I am using the ASIHTTPRequest library in an attempt to access the
> > Zotero API via GET, POST, etc.
>
> > I keep getting the error,
>
> > "You must specify a key to access the Zotero API."
>

> You must add a parameter 'key' containing a valid API key to the request. Seehttp://www.zotero.org/support/dev/server_api/read_api#authentication

Stephan Hügel

unread,
Nov 23, 2011, 11:57:19 AM11/23/11
to zoter...@googlegroups.com
On Wednesday, 23 November 2011 16:46:16 UTC, Richard Lent wrote:
Thanks for your reply Mikko. At this point I'm just trying to learn
the Zotero API to see what's possible in an iOS app. I'm ok with the
read API but am having trouble with how to specify a key for the write
API, so that items could be added and edited to an online library.

You specify it in exactly the same way as for Read API requests. You can use the same key, in fact, so long as you assign it write permissions on https://www.zotero.org/settings/keys first. 
Reply all
Reply to author
Forward
0 new messages