Unable to pull data from API using file_get_contents() - php

I am trying to pull data from API, and getting this error. I have searched same file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known
but did't understand how to fix
file_get_contents(): php_network_getaddresses: getaddrinfo failed:
Name or service not known
Here is my code
<?php namespace AdClass;
use stdClass;
class AdInfo{
private $domain;
private $widget_id;
private $api_key;
private $pub_id;
public function __construct($domain, $widget_id, $api_key, $pub_id)
{
$this->domain = $domain;
$this->widget_id = $widget_id;
$this->api_key = $api_key;
$this->pub_id = $pub_id;
}
public function getDomain()
{
return $this->domain;
}
public function getWidgetId()
{
return $this->widget_id;
}
public function getApiKey()
{
return $this->api_key;
}
public function getPubId()
{
return $this->pub_id;
}
public function getAdContent()
{
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.revcontent.com/api/v1',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'api_key' => $this->api_key,
'pub_id' => $this->pub_id,
'widget_id' => $this->widget_id,
'domain' => $this->domain,
'format' => 'json',
'sponsored_offset' => '0',
'internal_count' => '3',
'internal_offset' => '2'
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
return $resp;
}
}
?>
index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include(dirname(__FILE__).'/AdClass/AdInfo.php');
$domain = "realtimepolitics.com";
$widget_id = XXXX;
$api_key = "XXXXXX";
$pub_id = XXXX;
$adobj = new AdClass\AdInfo($domain, $widget_id, $api_key, $pub_id);
$response = $adobj->getAdContent();
echo "<pre>";
print_r($response);

Issue Fixed with cURL request:
<?php namespace AdClass;
use stdClass;
class AdInfo{
private $domain;
private $widget_id;
private $api_key;
private $pub_id;
private $sponsored_offset;
private $sponsored_count;
private $internal_offset;
private $internal_count;
public function __construct($domain,$widget_id,$sponsored_count=1,$internal_offset=1, $sponsored_offset=0,$internal_count=3)
{
$this->domain = $domain;
$this->widget_id = $widget_id;
$this->api_key = "XXXX";
$this->pub_id = xxxx;
$this->sponsored_offset =$sponsored_offset;
$this->sponsored_count = $sponsored_count;
$this->internal_offset = $internal_offset;
$this->internal_count = $internal_count;
}
public function getAdContent()
{
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://trends.revcontent.com/api/v1/?api_key='.$this->api_key.'&pub_id='.$this->pub_id.'&widget_id='.$this->widget_id.'&domain='.$this->domain.'&format=json&sponsored_count='.$this->sponsored_count.'&sponsored_offset='.$this->sponsored_offset.'&internal_count='.$this->internal_count.'&internal_offset='.$this->internal_offset ,
CURLOPT_USERAGENT => 'cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
return $resp;
}
}
?>
Main.php
<?php namespace MainApi;
include(dirname(__FILE__).'/../AdClass/AdInfo.php');
use AdClass\AdInfo;
class Main{
private $adObj;
public function __construct($domain,$widget_id,$sponsored_count,$internal_offset, $sponsored_offset,$internal_count)
{
$this->domain = $domain;
$this->widget_id = $widget_id;
$this->sponsored_offset =$sponsored_offset;
$this->sponsored_count = $sponsored_count;
$this->internal_offset = $internal_offset;
$this->internal_count = $internal_count;
$this->adObj = new AdInfo($this->domain,$this->widget_id,$this->sponsored_count,$this->internal_offset, $this->sponsored_offset,$this->internal_count);
}
function getResponse()
{
$response = $this->adObj->getAdContent();
return $response;
}
}
getAds.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include (dirname(__FILE__) . '/MainApi/Main.php');
$domain = "realtimepolitics.com";
$widget_id = $_GET['widget_id']; //97862
$weight = $_GET['w'];
$height = $_GET['h'];
$sponsored_count = 2;
$internal_offset = 2;
$sponsored_offset = 0;
$internal_count = 3;
$main = new MainApi\Main($domain, $widget_id, $sponsored_count, $internal_offset, $sponsored_offset, $internal_count);
$response = $main->getResponse();
$ads_data = json_decode($response);
print_r($ads_data);

Related

Error Loading Messages using Wialon Remote API

We have several GPS installed in different units and I am trying to retrieve the messages using the Wialon's Remote API but i am getting this error, can someone please help me? Thanks a lot!:
{"error":4, "reason":"VALIDATE_PARAMS_ERROR: {itemId: long, timeFrom: uint, timeTo: uint, flags: uint, flagsMask: uint, loadCount: uint}"}
Below is my script:
<?php
include('wialon.php');
$wialon_api = new Wialon();
$token = '{token here}';
$result = $wialon_api->login($token);
$json = json_decode($result, true);
if(!isset($json['error'])){
echo $wialon_api->messages_load_interval('{"itemId":24611387,"lastTime":1073741831,"lastCount":1,"flags":0,"flagMask":0,"loadCount":1}');
$wialon_api->logout();
} else {
echo WialonError::error($json['error']);
}
?>
Here is the Wialon Class which i downloaded from their site:
<?php
/* Classes for working with Wialon RemoteApi using PHP
*
* License:
* The MIT License (MIT)
*
* Copyright:
* 2002-2015 Gurtam, http://gurtam.com
*/
/** Wialon RemoteApi wrapper Class
*/
class Wialon{
/// PROPERTIES
private $sid = null;
private $base_api_url = '';
private $default_params = array();
/// METHODS
/** constructor */
function __construct($scheme = 'https', $host = 'hst-api.wialon.com', $port = '', $sid = '', $extra_params = array()) {
$this->sid = '';
$this->default_params = array_replace(array(), (array)$extra_params);
$this->base_api_url = sprintf('%s://%s%s/wialon/ajax.html?', $scheme, $host, mb_strlen($port)>0?':'.$port:'');
}
/** sid setter */
function set_sid($sid){
$this->sid = $sid;
}
/** sid getter */
function get_sid(){
return $this->sid;
}
/** update extra parameters */
public function update_extra_params($extra_params){
$this->default_params = array_replace($this->default_params, $extra_params);
}
/** RemoteAPI request performer
* action - RemoteAPI command name
* args - JSON string with request parameters
*/
public function call($action, $args){
$url = $this->base_api_url;
if (stripos($action, 'unit_group') === 0) {
$svc = $action;
$svc[mb_strlen('unit_group')] = '/';
} else {
$svc = preg_replace('\'_\'', '/', $action, 1);
}
$params = array(
'svc'=> $svc,
'params'=> $args,
'sid'=> $this->sid
);
$all_params = array_replace($this->default_params , $params);
$str = '';
foreach ($all_params as $k => $v) {
if(mb_strlen($str)>0)
$str .= '&';
$str .= $k.'='.urlencode(is_object($v) || is_array($v) ? json_encode($v) : $v);
}
/* cUrl magic */
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $str
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
if($result === FALSE)
$result = '{"error":-1,"message":'.curl_error($ch).'}';
curl_close($ch);
return $result;
}
/** Login
* user - wialon username
* password - password
* return - server response
*/
public function login($token) {
$data = array(
'token' => urlencode($token),
);
$result = $this->token_login(json_encode($data));
$json_result = json_decode($result, true);
if(isset($json_result['eid'])) {
$this->sid = $json_result['eid'];
}
return $result;
}
/** Logout
* return - server responce
*/
public function logout() {
$result = $this->core_logout();
$json_result = json_decode($result, true);
if($json_result && $json_result['error']==0)
$this->sid = '';
return $result;
}
/** Unknonwn methods hadler */
public function __call($name, $args) {
return $this->call($name, count($args) === 0 ? '{}' : $args[0]);
}
}
/** Wialon errorCode to textMessage converter
*/
class WialonError{
/// PROPERTIES
/** list of error messages with codes */
public static $errors = array(
1 => 'Invalid session',
2 => 'Invalid service',
3 => 'Invalid result',
4 => 'Invalid input',
5 => 'Error performing request',
6 => 'Unknow error',
7 => 'Access denied',
8 => 'Invalid user name or password',
9 => 'Authorization server is unavailable, please try again later',
1001 => 'No message for selected interval',
1002 => 'Item with such unique property already exists',
1003 => 'Only one request of given time is allowed at the moment'
);
/// METHODS
/** error message generator */
public static function error($code = '', $text = ''){
$code = intval($code);
if ( isset(self::$errors[$code]) )
$text = self::$errors[$code].' '.$text;
$message = sprintf('%d: %s', $code, $text);
return sprintf('WialonError( %s )', $message);
}
}
?>

getting error calling WCF SOAP web service through PHP

I have a WCF web service hosted on IIS. It can be called through .net with no problem. but when I try to call it via PHP I get This error
object(SoapFault)#5 "Cannot process the message because the content type 'application/soap+xml; charset=utf-8; action="web service URL"' was not the expected type 'text/xml; charset=utf-8'.
Here is my code
<?php
$X = new X ([
'Card' => '53535',
'Terminal' => '43534534',
'Amount' => '1000',
'OrderId' => '1',
'ReturnUrl' => 'test url',
'Password' => 'D414305754BE7625CA70D',
'MobileNo' => '03003030',
'AdditionalData' => 'test' ]);
$request_key = $X ->request(2, 1000, 'http://');
class WebServicePaymentRequest
{
public $Card = "53535";
public $Terminal = "43534534";
public $Amount = "1000";
public $OrderId = "1";
public $ReturnUrl = "test url";
public $Password = "D414305754BE7625CA70D";
public $MobileNo = "03003030";
}
class X {
private $Card;
private $Terminal;
private $Amount;
private $OrderId;
private $ReturnUrl;
private $Password;
private $MobileNo;
private $AdditionalData;
private $Token;
private $wsdl_url = 'https://XXX/WebServices/PaymentUtils.svc?wsdl';
public function __construct($params)
{
$this->Card = $params['Card'];
$this->Terminal = $params['Terminal'];
$this->Password = $params['Password'];
$this->Amount = $params['Amount'];
$this->OrderId = $params['OrderId'];
$this->ReturnUrl = $params['ReturnUrl'];
$this->MobileNo = $params['MobileNo'];
$this->AdditionalData = $params['AdditionalData'];
}
public function request($order_id, $amount, $callback)
{
$options = array(
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_NONE,
"exceptions" => false,
"encoding"=> 'UTF-8'
);
$client = new SoapClient($this->wsdl_url, $options);
$obj = new WebServicePaymentRequest;
$obj->Amount = $amount; // Output the property
$obj->OrderId = $order_id;
$obj->ReturnUrl = $callback;
$result = $client->PaymentRequest($obj);
echo $result;
var_dump($result);
$result = json_decode($result, true);
$this->Token = $result['Token'];
}
}
?>
I tried every solution in stackoverflow and other websites. but it did not work .
Thanks in Advance...
I found out that Soapclient does not support WCF in PHP .I solved the problem by Posting Xml as Body with SoapAction header to The Url. I used SoapUi to get the Xml , and then postman to get the result.

WordPress - Issues with referencing custom PHP class in functions.php

I apologize if this is really dumb/obvious but this is my first experience working with classes in WordPress.
I made a class called SharpSpringService.php inside my custom plugin sharpspring-form. I placed the class within a classes folder within that custom plugin for organization purposes.
I'm referencing the SharpSpringService class within a function in functions.php but am getting an error. When I declare a new instance of SharpSpringService and place the account ID and secret key as parameters, I get a message: "Expected SharpSpring, got string". I also see an Internal Server 500 Error in the Chrome dev consoles that seems to be a result of creating an instance of this class.
I'm not sure why the parameters are expected to be "SharpSpring" as they should be accountID and secretkey.
Here is the SharpSpringService class:
private $authError = false;
private $accountID = null;
private $secretKey = null;
/**
* SharpSpringService constructor.
* #param $accountID SharpSpring Account ID
* #param $secretKey SharpSpring Secret Key
*/
public function __construct($accountID, $secretKey)
{
$this->accountID = $accountID;
$this->secretKey = $secretKey;
}
public function hasAuthError() {
return $this->authError;
}
public function makeCall($method, $params = []) {
$requestID = session_id();
$accountID = $this->accountID;
$secretKey = $this->secretKey;
$data = array(
'method' => $method,
'params' => $params,
'id' => $requestID,
);
$queryString = http_build_query([
'accountID' => $accountID,
'secretKey' => $secretKey
]);
$url = "http://api.sharpspring.com/pubapi/v1/?$queryString";
$data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
));
$result = curl_exec($ch);
curl_close($ch);
$resultObj = json_decode($result);
if ($resultObj->error != null) {
throw new \Exception($result->error);
}
return $resultObj;
}
}
And here is the function in functions.php that is referencing the class:
function get_memberships_callback(){
$newsListID = 550280195;
$listName = "NewsList";
$contactEmail = $_POST['contactemail'];
$sharpSpringService = new SharpSpringService('[redacted]', '[redacted]'); //this is where the code chokes
$return = [];
if($contactEmail != null && $contactEmail !=""){
$lists = $sharpSpringService->makeCall('getListMemberships', [
'emailAddress' => $contactEmail,
]);
if (count($lists) > 0) {
$listArray = json_decode(json_encode($lists), true);
$inNewsList = false;
foreach($listArray as $list){
if($list = $newsListID){
//the user is subscribed to the news list
$inNewsList = true;
$converted_result = ($inNewsList) ? 'true' : 'false';
}
}
}
$return[] = array(
"status" => $converted_result,
"list" => $listName
);
return json_encode($return);
}
else{
return $return;
}
die();
}
For calling numerous files, it is sometimes convenient to define a constant:
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
include( MY_PLUGIN_PATH . 'includes/admin-page.php');
include( MY_PLUGIN_PATH . 'includes/classes.php');

How to find out what Curl values to enter in WP remote posting script

Found this handy little script that uses Curl and PHP to use the Wordpress XML-RPC function to post directly to my Wordpress blog. I think I have figured out where to enter most information, but there are two values I just can't figure out (not with any amount of Google searching either - so far).
Below I put the entire script, which others may use - provided by http://blog.artooro.com/2012/09/03/wordpress-api-xml-rpc-new-easy-to-use-php-class/
The two values I can't figure out are "ch" and "execute". Not sure if this is a Curl value or a PHP value.
class WordPress {
private $username;
private $password;
private $endpoint;
private $blogid;
private $ch;
public function __construct($username, $password, $endpoint, $blogid = 1) {
$this->myusername = $username;
$this->mypassword = $password;
$this->my-site.com/xmlrpc.php = $endpoint;
$this->1 = $blogid;
$this->ch = curl_init($this->my-site.com/xmlrpc.php);
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
}
private function execute($request) {
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($this->ch);
$result = xmlrpc_decode($response);
if (is_array($result) && xmlrpc_is_fault($result)) {
throw new Exception($result['faultString'], $result['faultCode']);
}
else {
return $result;
}
}
public function publish_post($title, $content, array $tags, array $categories, $status = 'publish', $date = Null) {
// Set datetime for post
if ($date == Null) {
$post_date = date("Ymd\TH:i:s", time());
}
else {
$post_date = $date;
}
xmlrpc_set_type($post_date, 'datetime');
$params = array(
$this->id,
$this->myusername,
$this->mypassword,
array(
'post_type' => 'post',
'post_status' => $status,
'post_title' => $title,
'post_content' => $content,
'post_date' => $post_date,
'terms_names' => array('category' => $categories, 'post_tag' => $tags)
)
);
$request = xmlrpc_encode_request('wp.newPost', $params);
$response = $this->execute($request);
return $response;
}
}
$this->ch = Curl Handle, its the property that will hold the curl request handle. Its private as it will not be used outside of the class.
$this->execute() = Is the class method that will execute the curl request and return the result. Its private as it will not be used outside of the class.
Both are part of the class and not part of PHP internals.
Also:
I see a couple of problems with the code provided:
$this->my-site.com/xmlrpc.php = $endpoint; should be
$this->endpoint = $endpoint;
$this->1 = $blogid; should be $this->blogid = $blogid;
Plus change references to them properties within the publish_post() method.
Fixed code:
<?php
/*Usage:*/
$wordpress = new WordPress($username, $password, 'my-site.com/xmlrpc.php', 1);
$wordpress->publish_post(...);
class WordPress {
private $username;
private $password;
private $endpoint;
private $blogid;
private $ch;
public function __construct($username, $password, $endpoint, $blogid = 1) {
$this->myusername = $username;
$this->mypassword = $password;
$this->endpoint = $endpoint;
$this->blogid = $blogid;
$this->ch = curl_init($this->endpoint);
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
}
private function execute($request) {
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($this->ch);
$result = xmlrpc_decode($response);
if (is_array($result) && xmlrpc_is_fault($result)) {
throw new Exception($result['faultString'], $result['faultCode']);
}
else {
return $result;
}
}
public function publish_post($title, $content, array $tags, array $categories, $status = 'publish', $date = Null) {
// Set datetime for post
if ($date == Null) {
$post_date = date("Ymd\TH:i:s", time());
}
else {
$post_date = $date;
}
xmlrpc_set_type($post_date, 'datetime');
$params = array(
$this->blogid,
$this->myusername,
$this->mypassword,
array(
'post_type' => 'post',
'post_status' => $status,
'post_title' => $title,
'post_content' => $content,
'post_date' => $post_date,
'terms_names' => array('category' => $categories, 'post_tag' => $tags)
)
);
$request = xmlrpc_encode_request('wp.newPost', $params);
$response = $this->execute($request);
return $response;
}
}
?>
hope it helps

How to get Citrix's Goto Meeting Access Token

Hi i am trying to get Goto meeting OAuth access token via php curl. but it returns nothing when i make a call. please guide me how i can get it, Code is given below.
$api_key = "123456";
$redirect_url = urlencode("URL");
$webinar_url = "https://api.citrixonline.com/oauth/authorize?client_id=".$api_key."&redirect_uri=".$redirect_url;
function getWebinarData($link)
{
$headers = array(
"HTTP/1.1",
"Content-type: application/json",
"Accept: application/json"
);
$curl = curl_init($link);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //2
$response = curl_exec($curl);
echo "<pre>DATA: ";print_r($response);echo "</pre>";
curl_close($curl);
return $response;
}
/**
* goto api
* Author: Ahad Ali
* Date: valentines day 2013
* Classes Curl, OAuth, GotoTraining
*/
define ("API_KEY", "");
define ("REDIRECT_URL","");
define ("AUTH_AUTOLOGIN_URL","https://developer.citrixonline.com/oauth/g2t/authorize.php");
define ("AUTH_EXCHANGE_URL", "https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code=<CODE>&client_id=" . API_KEY);
define ("MANAGE_TRAINING_URL","https://api.citrixonline.com/G2T/rest/organizers/<ORGANIZERKEY>/trainings");
class Curl
{
public $result;
public function __construct()
{
}
public function request($url, $data="", $method="get", $headers="")
{
$ch = curl_init();
// this is autologiM USING CURL POST
// avoiding the redirect to gotos site where it asks for email and password and redirects back to the URL with a code
curl_setopt($ch, CURLOPT_URL, $url);
if($method == "post")
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
}
if($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$this->result = (string) curl_exec($ch);
curl_close($ch);
return $this->result;
}
public function __destruct()
{
}
}
class OAuth
{
public $autologin_url;
public $exchange_url;
public $code;
public $auth_result;
//https://api.citrixonline.com/oauth/authorize?client_id= used this URL to get all the field names
public $login_data = array(
'emailAddress' => '',
'password' => '',
'client_id' => '',
'access_type'=> 'G2T',
'app_name' => '',
'redirect_uri' => '',
'submitted' => 'form_submitted',
);
public function __construct($autologin_url = AUTH_AUTOLOGIN_URL, $exchange_url = AUTH_EXCHANGE_URL, $apikey=API_KEY)
{
$this->autologin_url = $autologin_url;
$this->exchange_url = $exchange_url;
$this->login_data['client_id'] = $apikey;
}
public function authorize()
{
$this->getCode();
$this->exchangeCodeForAccessToken();
}
public function getCode()
{
$curl = new Curl();
$result = $curl->request($this->autologin_url, $this->login_data, "post");
$arr = explode("\n", $result);
foreach($arr as $k=>$v)
{
if(strstr($v,"Location: http:"))
$return_url = $v;
}
$query = trim(parse_url($return_url, PHP_URL_QUERY));// adds one unnecessary _ (underscore) at the end of the query string
$this->code = substr($query, 5, (strlen($query) - 6));//starting from 5 get me ...number of chars
}
function exchangeCodeForAccessToken()
{
$this->exchange_url = str_replace("<CODE>", $this->code, $this->exchange_url);
$curl = new Curl();
$result = $curl->request($this->exchange_url);
$this->auth_result = json_decode($result);
}
public function __destruct()
{
}
}
class GotoTraining extends OAuth
{
public $manage_training_url;
public $training_result;
public $error_list = array("AuthFailure", "AccessDenied", "ExpiredToken", "InternalError", "InvalidRequest", "InvalidMethod", "MissingToken", "NoSuchTraining", "InvalidToken");
public function __construct($url = MANAGE_TRAINING_URL)
{
$this->manage_training_url = $url;
parent::__construct();
}
/**
*Arguement List for goto CreateTraining service
* [name] => Representational State Transfer 101
[description] => The REST-ful way to APIs.
[timeZone] => America/Los_Angeles
[times] => Array
(
[0] => stdClass Object
(
[startDate] => 2011-09-08T18:25:00Z
[endDate] => 2011-09-08T19:25:00Z
)
[1] => stdClass Object
(
[startDate] => 2011-09-09T18:25:00Z
[endDate] => 2011-09-09T19:25:00Z
)
)
[registrationSettings] => stdClass Object
(
[disableWebRegistration] => false
[disableConfirmationEmail] => false
)
[organizers] => Array
(
[0] => 6512477
[1] => 38712
[2] => 9876466
)
*/
public function createTraining($name, $desc, $times)
{
$registrationSettings["disableWebRegistration"] = "false";
$registrationSettings["disableConfirmationEmail"] = "false";
$json["name"] = $name;
$json["description"] = $desc;
$json["timeZone"] = "Australia/Sydney";
$json["times"] = $times;//array for startDate, endDate
$json["registrationSettings"] = $registrationSettings;
$json["organizers"][0] = $this->auth_result->organizer_key;
$this->manage_training_url = str_replace("<ORGANIZERKEY>", $this->auth_result->organizer_key, $this->manage_training_url);
$json = json_encode($json);
//$post_data[] = "Authorization:OAuth oauth_token=" . $this->auth_result->access_token;
//$this->manage_training_url = $this->manage_training_url . "?oauth_token=" . $this->auth_result->access_token;
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: OAuth oauth_token=' . $this->auth_result->access_token
);
//$this->manage_training_url = $this->manage_training_url . "?oauth_token=" . $this->auth_result->access_token;
$curl = new Curl();
$this->training_result = $curl->request($this->manage_training_url, $json, "post", $headers);
$arr = explode("\n", $this->training_result);
$this->webCode = trim($arr[count($arr)-1], '"');
$this->checkError();
return $this->webCode;
}
public function checkError()
{
foreach($this->error_list as $val)
{
if(strstr($this->training_result, $val))
$this->webCode = $val;
}
return 0;
}
}

Categories