Question

The documentation for Wordpress Jetpack plugin dose not really offer a step by step guide on how to get everything set up for querying your wordpress site using the Json Rest API.

However I have managed to get to the point where I can query my sites posts, which I guess means I have these steps set up correctly.

A, set the wordpress site up correctly 
B, installed jetpack correctly and 
C, set up my developers account with wordpress and registered my
app.

My goal is to set up a business directory where I can access the user generated data from an iphone application I will write, I plan to use NSURLConnection to send my queries and I will store the returning Json data into CoreData on the phone.

I have set up s2Member on word press which allows people to join my site at $XX.XX cost to them, after payment they can then fill in their account detials which includes a section about their business. i.e. name, address and contact details etc.

I would like to know how to access this user information. For instance I had hoped that I could do a single query which would return to me every single members details that I would then save into coredata/phone cache. However I am not sure how to do this.

What I had though about using was https://developer.wordpress.com/docs/api/1/get/me/ but I'm not sure if this will return the business information I am after and I'm not really sure how to construct the request using the example code on the page

cURL

curl \
 -H 'authorization: Bearer YOUR_API_TOKEN' \
 'https://public-api.wordpress.com/rest/v1/me/?pretty=1'

How would I turn this into a NSURLRequest for my app's NSURLConnection?

Was it helpful?

Solution

So it seems you're trying to figure out how to setup an HTTP request with custom headers. Something like this:

NSURL *url = [NSURL URLWithString:@"https://public-api.wordpress.com/rest/v1/me/?pretty=1"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"Bearer YOUR_API_TOKEN" forHTTPHeaderField:@"authorization"];

You then fire off the request using the networking API of your choice (I recommend NSURLSession for any new development).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top