0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
HurkNburkS
  • 5,492
  • 19
  • 100
  • 183

1 Answers1

1

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).

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
  • the authorization part of the curl example is what I am having problems with. where dose that fit into things? – HurkNburkS Dec 29 '13 at 10:13
  • This is the error I am getting with your code "2013-12-29 23:17:30.578 guideTest[933:c07] 2013-12-29 23:17:32.331 guideTest[933:c07] { "error": "authorization_required", "message": "An active access token must be used to query information about the current user."" – HurkNburkS Dec 29 '13 at 10:20
  • okay great.. i understand that I just need to figure out where to find my app api token then.. I have a client ID and client secret.. but i canot find the token. – HurkNburkS Dec 29 '13 at 10:30
  • this worked I had to go through the 0Auth process to get the app token. – HurkNburkS Dec 29 '13 at 10:39