WordPress.Com: Stats Views

Wordpress.Com: Stats Views
Gets a post’s views. By specifying WORDPRESS-DOMAIN and POST’ID, the cumulative number of page views is stored.
https://support.questetra.com/addons/wordpress-com-stats-views/
2018-12-12 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • B: Set WORDPRESS DOMAIN (e.g. “example.com” or ID) * #{EL}
  • C: Set POST ID (e.g. “1234”) * #{EL}
  • D: Select STRING/NUMERIC DATA for #Views (update) *
Script
// (c) 2018, Questetra, Inc. (the MIT License)

//// == OAuth2 Setting example ==
// Authorization Endpoint URL:
//  "https://public-api.wordpress.com/oauth2/authorize"
// Token Endpoint URL:
//  "https://public-api.wordpress.com/oauth2/token"
// Scope: "global" (or "auth")
// Client ID: ( from https://developer.wordpress.com/apps/ )
// Consumer Secret: ( from https://developer.wordpress.com/apps/ )
// -- "Redirect URLs": "https://s.questetra.net/oauth2callback"
// -more-
// https://developer.wordpress.com/docs/oauth2/
// https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/stats/post/%24post_id/


//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const oauth2   = configs.get( "conf_OAuth2" ) + "";
const wpDomain = configs.get( "conf_WpDomain" ) + "";
const postId   = configs.get( "conf_PostId" ) + "";
const dataIdD  = configs.get( "conf_DataIdD" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'
if(postId === ""){
  throw new Error( '\n PostID not Defined \n' );
}
if(wpDomain === ""){
  throw new Error( '\n WordPress Domain not Defined \n' );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==
/// obtain OAuth2 Access Token
const token   = httpClient.getOAuth2Token( oauth2 );

/// prepare API Request
let apiRequest = httpClient.begin(); // HttpRequestWrapper
// - com.questetra.bpms.core.event.scripttask.HttpClientWrapper
apiRequest     = apiRequest.bearer( token );
apiRequest     = apiRequest.queryParam( "fields", "views" );

/// access API (with post(), get(), put(), etc.)
const apiUri = "https://public-api.wordpress.com/rest/v1.1/sites/"
               + wpDomain + "/stats/post/" + postId;
const response = apiRequest.get( apiUri );
// - HttpResponseWrapper
const httpStatus  = response.getStatusCode() + "";
engine.log( "STATUS: " + httpStatus );
const responseStr = response.getResponseAsString() + "";
engine.log( "RESPONSE: \n" + responseStr );

/// parse Response-JSON
const responseObj = JSON.parse( responseStr );


//// == Data Updating / ワークフローデータへの代入 ==
if( engine.findDataDefinitionByNumber( dataIdD ).matchDataType( "DECIMAL" ) ){
  engine.setDataByNumber( dataIdD, new java.math.BigDecimal(responseObj.views) );
}else{
  engine.setDataByNumber( dataIdD, responseObj.views );
}

} //////// END "main()" ////////

Download

WordPressCom-Stats-Views.xml
WordPressCom-Stats-Views.xml

Capture

See also

WordPress.Com: Media New

2 thoughts on “WordPress.Com: Stats Views”

  1. Pingback: My Experience Story on SaaS WordPress - Questetra

  2. Pingback: WordPress.Com: Posts New – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top