Skip to content

Commit

Permalink
Merge pull request #10 from Automattic/update/usage-instructions
Browse files Browse the repository at this point in the history
Update usage instructions to be clearer on how to use the access token
  • Loading branch information
oskosk committed Feb 24, 2017
2 parents 8c8f274 + 8badc6b commit d278784
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ var wpcomOAuth = require('wpcom-oauth-cors')('<client-id>');

// get auth object
wpcomOAuth.get(function(auth){
// your token is here auth.access_token!
// Here, your token is available as auth.access_token
// e.g.:
// var wpcom = require('wpcom');
// var wpc = wpcom(auth.access_token);
});

// clean stored token
Expand Down Expand Up @@ -53,6 +56,27 @@ Create a wpcomOAuth instance giving `client_id` (String) and optional parameters

### wpcomOAuth.token()


## Example

This snippet will log a posts array from site with id `123456`.

```js
var wpcom = require('wpcom');
var wpcomOAuth = require('wpcom-oauth-cors')('<client-id>');

// get auth object
wpcomOAuth.get(function(auth){
// Here, your token is available as auth.access_token
var wpc = wpcom( auth.access_token );
var mySite = wpc.site( 123456 );
mySite.postsList({ number: 50, fields: "author,URL,title,geo" }, function(err, list) {
console.log( list );
});
});

```

## Test

* Compile testing js file
Expand Down

0 comments on commit d278784

Please sign in to comment.