PHP script works fine only on localhost - json

I'm using this script for parsing an URL that contain a JSON structure. Works fine on localhost (XAMPP) but doesn't work on server side. Anyone have some suggestion about this? I can't find any solutions...
EDIT: The problem is the HOSTING of my website where the script run. It allow communication only on port 80 and 443. There are solutions?
<?php
function session_type($type) {
switch ($type) {
case 0:
return "Booking";
break;
case 1:
return "Pratica";
break;
case 2:
return "Qualifica";
break;
case 3:
return "Gara";
break;
default:
return "Error";
break;
}
}
$server = "http://95.141.37.33:8098/INFO";
$ch = curl_init($server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output = curl_exec($ch);
curl_close($ch);
$sjson = json_decode($output, true);
echo 'Current Track: ' . $sjson['track'] . '<br />';
echo 'Name: '. $sjson['name'] . '<br />';
echo 'Utenti Online: '. $sjson['clients'] . '<br />';
foreach ($sjson['cars'] as $key=>$value)
{
echo "Auto:". $value ."<br />";
};
echo 'Port: '. $sjson['port'] . '<br />';
echo 'Sessione: ' . session_type($sjson['session']) . '<br />';
echo 'Timeleft: '. $sjson['timeleft'] . '<br />';
$users = "http://95.141.37.33:8098/JSON|";
$ch = curl_init($users);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output_user = curl_exec($ch);
curl_close($ch);
$ujson = json_decode($output_user, true);
echo 'Racers: <br />';
foreach ($ujson as $key => $jsons) {
foreach ($jsons as $key => $value) {
echo $value['DriverName'] . '<br />';
}
}
?>
Thanks in advance

Related

How to PHP Convertapi HTML to PDF without physcal HTML file

i wish to convert an html document, which is stored as a string ($html) into PDF using convertAPI via CURL (ie no physical file)
i don't understand how I need to post the $html to the API, i was looking at the example on the convertapi webpage, but i don't seem to be able to make sense of it.
example pasted below.
$html = '<hmtl file contents>' ;
$parameters = array(
'Secret' => 'X?X?X?X?X?X?X',
);
function convert_api($src_format, $dst_format, $files, $parameters) {
$parameters = array_change_key_case($parameters);
$auth_param = array_key_exists('secret', $parameters) ? 'secret='.$parameters['secret'] : 'token='.$parameters['token'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/{$src_format}/to/{$dst_format}?{$auth_param}");
if (is_array($files)) {
foreach ($files as $index=>$file) {
$parameters["files[$index]"] = file_exists($file) ? new CurlFile($file) : $file;
}
} else {
$parameters['file'] = file_exists($files) ? new CurlFile($files) : $files;
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$error = curl_error($curl);
curl_close($curl);
if ($response && $httpcode >= 200 && $httpcode <= 299) {
return json_decode($response);
} else {
throw new Exception($error . $response, $httpcode);
}
}
thank you
Try this short example:
$secret = 'XXXXXXXXXX';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/octet-stream', 'Accept: application/octet-stream', 'Content-Disposition: attachment; filename="file.html"'));
curl_setopt($curl, CURLOPT_URL, "https://v2.convertapi.com/html/to/pdf?secret=".$secret);
curl_setopt($curl, CURLOPT_POSTFIELDS, '<!doctype html><html lang=en><head><meta charset=utf-8><title>Conversion test</title></head><body>This is html body</body></html>');
$result = curl_exec($curl);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
file_put_contents("result.pdf", $result);
} else {
print("Server returned error:\n".$result."\n");
}
More examples can be found at: https://repl.it/#ConvertAPI

json api not working in server

i am develop one bitcoin website, i m include the live price tricket, it is working in localhost, when i upload in sever it is not working the code is
<?php
$f="http://api.coindesk.com/v1/bpi/currentprice/INR.json";
$file=file_get_contents($f);
$myjson = json_decode($file);
print "<li>BPI:".$myjson->bpi->INR->rate;
print "<li>disclaimer:".$myjson->disclaimer;
?>
in local i m get result this
after upload i m get this result
Check whether allow_url_fopen is set true in PHP on your live server. If is false ask your server hosting support to set it to true
If server doesn't allow making it true you can try following
$url = "http://api.coindesk.com/v1/bpi/currentprice/INR.json";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$contents = '';
} else {
curl_close($ch);
}
if (!is_string($contents) || !strlen($contents)) {
echo "Error reading data"l
}
else{
$myjson = json_decode($contents);
echo "<li>BPI:".$myjson->bpi->INR->rate;
echo "<li>disclaimer:".$myjson->disclaimer;
}

import google contact and parse image code

my script for importing gmail contacts work as well , it return name , email , and image but i dont know how to display the image in the html tag . the code json of image returned is like this:
"ôÆÔÔmr½k/8I16¹&ÂÂæöì=†çlk'qËüoÍÒ8äLåLŽáZ³GrF§i)%#’ŽHÔ6ØØ•Âþds˜%h¤‚Ÿ2¨‘Þ—ÖyDÛVºbè¢ýCEuî*RT´l« Ã)GúAËÑï |Î幡XÝÍ-Clr¡Y½’aòg°ùl{Tã‘ÔYúHÁRŠÁ2EKP"7Ô¢R]‹(keëà‡Ž5YÎf­ÈÖ^JÈÈUâ%C´&ü—b¥¹l,Nþã0ÏÂ|CauÒ,°H5#¯CØ‚:†SpÊÖA0ñ€ÂqG|Ûø§.o,ÔW9u×W"²¨‘‘•HÔÄ)TˆÑ?"
Thanks!!! :))
$return = array();
if (!empty($contacts['feed']['entry'])) {
foreach($contacts['feed']['entry'] as $contact) {
//retrieve user photo
if (isset($contact['link'][0]['href'])) {
$url = $contact['link'][0]['href'];
$url = $url . '&access_token=' . urlencode($accesstoken);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$image = curl_exec($curl);
curl_close($curl);
}
$return[] = array (
'name'=> $contact['title']['$t'],
'email' => $contact['gd$email'][0]['address'],
'image' =>$image,
);
}
}
foreach ($return as $contact) {
$image=$contact['image'];
echo $image;?>
<br> <br> <br>
<img src="data:image/jpeg;base64,<?php echo $image ?>" /> <br>;
<?php
}

LinkedIn API - Setting user status saying unauthorised

So I've been following through various tutorials and documents to get this working and am really struggling. These are the files required for it to work:
Required Files
auth.php
<?php
session_start();
$config['base_url'] = '';
$config['callback_url'] = '';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# Now we retrieve a request token. It will be set as $linkedin->request_token.
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);
# With a request token in hand, we can generate an authorization URL, which we'll direct the user to.
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
header("Location: " . $linkedin->generateAuthorizeUrl()); ?>
demo.php
This is the script that I get after signup:
<?php
session_start();
$config['base_url'] = 'http://xxx/linkedin/auth.php';
$config['callback_url'] = 'http://xxx/linkedin/demo.php';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;} else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);}
# You now have a $linkedin->access_token and can make calls on behalf of the current member.
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)");
$id = $linkedin->getProfile('~:(id)');
$fname = $linkedin->getProfile('~:(first-name)');
$lname = $linkedin->getProfile('~:(last-name)');
$headline = $linkedin->getProfile('~:(headline)');
$picture = $linkedin->getProfile('~:(picture-url)');
$id = trim(strip_tags($id));
$fname = trim(strip_tags($fname));
$lname = trim(strip_tags($lname));
$headline = trim(strip_tags($headline));
$picture = trim(strip_tags($picture)); ?>
linkedin.php
This is linkedin library:
<?php require_once("OAuth.php"); class LinkedIn {
public $base_url = "http://api.linkedin.com";
public $secure_base_url = "https://api.linkedin.com";
public $oauth_callback = "oob";
public $consumer;
public $request_token;
public $access_token;
public $oauth_verifier;
public $signature_method;
public $request_token_path;
public $access_token_path;
public $authorize_path;
function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL)
{
if($oauth_callback) {
$this->oauth_callback = $oauth_callback;
}
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken";
$this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
$this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
}
function getRequestToken()
{
$consumer = $this->consumer;
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
$request->set_parameter("oauth_callback", $this->oauth_callback);
$request->sign_request($this->signature_method, $consumer, NULL);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function generateAuthorizeUrl()
{
$consumer = $this->consumer;
$request_token = $this->request_token;
return $this->authorize_path . "?oauth_token=" . $request_token->key;
}
function getAccessToken($oauth_verifier)
{
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
$request->set_parameter("oauth_verifier", $oauth_verifier);
$request->sign_request($this->signature_method, $this->consumer, $this->request_token);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->access_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function getProfile($resource = "~")
{
$profile_url = $this->base_url . "/v1/people/" . $resource;
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
# This PHP library doesn't generate the header correctly when a realm is not specified.
# Make sure there is a space and not a comma after OAuth
// $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
// # Make sure there is a space between OAuth attribute
// $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
// $response will now hold the XML document
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
function setStatus($status)
{
$profile_url = $this->base_url . "/v1/people/~";
$status_url = $this->base_url . "/v1/people/~/current-status";
echo "Setting status...\n";
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
echo $xml . "\n";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
# Parameters should be a query string starting with "?"
# Example search("?count=10&start=10&company=LinkedIn");
function search($parameters)
{
$search_url = $this->base_url . "/v1/people-search:(people:(id,first-name,last-name,picture-url,site-standard-profile-request,headline),num-results)" . $parameters;
//$search_url = $this->base_url . "/v1/people-search?keywords=facebook";
echo "Performing search for: " . $parameters . "<br />";
echo "Search URL: $search_url <br />";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($search_url, $auth_header, "GET");
return $response;
}
function httpRequest($url, $auth_header, $method, $body = NULL)
{
if (!$method) {
$method = "GET";
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header, "Content-Type: text/xml;charset=utf-8"));
}
$data = curl_exec($curl);
curl_close($curl);
return $data;
}}
The Problem
Trying to set the status
To set the status update I have tried using this in the demo.php file:
$setStatus = "Testing API";
$statusResponse = $linkedin->setStatus("~:($setStatus)");
echo '<pre>';
var_dump($statusResponse);
echo '</pre>';
But it is giving me this error:
Setting status... ~:(Testing API)
string(343) "
401
1407931633217
DW74ALZZVN
0
[unauthorized]. OAU:xxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxx|*01|*01:1407931633:eyA6PiJzKUJixQLLtaQL90wppHI=
"
P.S: I x'd out the key there, but they are correct and the rest of the script works with them.
How do I set the status of the authorised account? So I've been following through various tutorials and documents to get this working and am really struggling. These are the files required for it to work:
Required Files
auth.php
<?php
session_start();
$config['base_url'] = '';
$config['callback_url'] = '';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# Now we retrieve a request token. It will be set as $linkedin->request_token.
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);
# With a request token in hand, we can generate an authorization URL, which we'll direct the user to.
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
header("Location: " . $linkedin->generateAuthorizeUrl()); ?>
demo.php
This is the script that I get after signup:
<?php
session_start();
$config['base_url'] = 'http://xxx/linkedin/auth.php';
$config['callback_url'] = 'http://xxx/linkedin/demo.php';
$config['linkedin_access'] = '';
$config['linkedin_secret'] = '';
include_once "linkedin.php";
# The first step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback.
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;} else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);}
# You now have a $linkedin->access_token and can make calls on behalf of the current member.
$xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)");
$id = $linkedin->getProfile('~:(id)');
$fname = $linkedin->getProfile('~:(first-name)');
$lname = $linkedin->getProfile('~:(last-name)');
$headline = $linkedin->getProfile('~:(headline)');
$picture = $linkedin->getProfile('~:(picture-url)');
$id = trim(strip_tags($id));
$fname = trim(strip_tags($fname));
$lname = trim(strip_tags($lname));
$headline = trim(strip_tags($headline));
$picture = trim(strip_tags($picture)); ?>
linkedin.php
This is linkedin library:
<?php require_once("OAuth.php"); class LinkedIn {
public $base_url = "http://api.linkedin.com";
public $secure_base_url = "https://api.linkedin.com";
public $oauth_callback = "oob";
public $consumer;
public $request_token;
public $access_token;
public $oauth_verifier;
public $signature_method;
public $request_token_path;
public $access_token_path;
public $authorize_path;
function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL)
{
if($oauth_callback) {
$this->oauth_callback = $oauth_callback;
}
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken";
$this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
$this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
}
function getRequestToken()
{
$consumer = $this->consumer;
$request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
$request->set_parameter("oauth_callback", $this->oauth_callback);
$request->sign_request($this->signature_method, $consumer, NULL);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function generateAuthorizeUrl()
{
$consumer = $this->consumer;
$request_token = $this->request_token;
return $this->authorize_path . "?oauth_token=" . $request_token->key;
}
function getAccessToken($oauth_verifier)
{
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
$request->set_parameter("oauth_verifier", $oauth_verifier);
$request->sign_request($this->signature_method, $this->consumer, $this->request_token);
$headers = Array();
$url = $request->to_url();
$response = $this->httpRequest($url, $headers, "GET");
parse_str($response, $response_params);
$this->access_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}
function getProfile($resource = "~")
{
$profile_url = $this->base_url . "/v1/people/" . $resource;
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
# This PHP library doesn't generate the header correctly when a realm is not specified.
# Make sure there is a space and not a comma after OAuth
// $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
// # Make sure there is a space between OAuth attribute
// $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
// $response will now hold the XML document
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
function setStatus($status)
{
$profile_url = $this->base_url . "/v1/people/~";
$status_url = $this->base_url . "/v1/people/~/current-status";
echo "Setting status...\n";
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
echo $xml . "\n";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($profile_url, $auth_header, "GET");
return $response;
}
# Parameters should be a query string starting with "?"
# Example search("?count=10&start=10&company=LinkedIn");
function search($parameters)
{
$search_url = $this->base_url . "/v1/people-search:(people:(id,first-name,last-name,picture-url,site-standard-profile-request,headline),num-results)" . $parameters;
//$search_url = $this->base_url . "/v1/people-search?keywords=facebook";
echo "Performing search for: " . $parameters . "<br />";
echo "Search URL: $search_url <br />";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("https://api.linkedin.com");
$response = $this->httpRequest($search_url, $auth_header, "GET");
return $response;
}
function httpRequest($url, $auth_header, $method, $body = NULL)
{
if (!$method) {
$method = "GET";
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header)); // Set the headers.
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($auth_header, "Content-Type: text/xml;charset=utf-8"));
}
$data = curl_exec($curl);
curl_close($curl);
return $data;
}}
The Problem
Trying to set the staus
To set the status update I have tried using this in the demo.php:
$setStatus = "Testing API";
$statusResponse = $linkedin->setStatus("~:($setStatus)");
echo '<pre>';
var_dump($statusResponse);
echo '</pre>';
But it is giving me this error:
Setting status... ~:(Testing API)
string(343) "
401
1407931633217
DW74ALZZVN
0
[unauthorized]. OAU:xxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxx|*01|*01:1407931633:eyA6PiJzKUJixQLLtaQL90wppHI=
"
P.S: I x'd out the key there, but they are correct and the rest of the script works with them.
How do I set the status of the authorised account?
Not sure if it is still relevant, and the current-status API is deprecated, but the line:
$xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
needs to be changed to:
$xml = "" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "";

integrating a function

this is the follow-up to my question about getting a div's content. the second function is the one im having a hard time with. im pretty sure i can call a function from another one, but im not sure about placing them into oneanother like i did here. its obviously a silly attempt to make the code work, since it gives me an error:
Blackline Frostbyte : in stock. : $139.99
Fatal error: Cannot redeclare get_string_between() (previously declared in /home/rambazar/public_html/cron.php:69) in /home/rambazar/public_html/cron.php on line 69
as i see this, the code is partially ok, because it gets a products stock info and the price tag, but the code stops and i cant figure out where get_string_between is redeclared, as it is only called. please help me sorting this out, thanks!
<?php
set_time_limit(1800);
include("admin/include/db.php");
error_reporting(E_ALL);
$res=mysql_query("select * from products");
while($row=mysql_fetch_array($res))
{
$availability=getavailability($row['newegg_productid']);
$price=getprice($row['newegg_productid']);
echo $row['productname']." : ".$availability." : ".$price."<br />";
}
function getavailability($itemId)
{
$url=trim("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
$ch = curl_init();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($ch);
curl_close ($ch);
$content=strtolower($content);
$buff=$content;
$isAvailable=false;
$pos1=strpos($content,'<p class="note">')+16;
if($pos1==16)return "";
$pos2=strpos($content,'</p>',$pos1);
$availability= trim(substr($content,$pos1,($pos2-$pos1)));
return strip_tags($availability);
}
function getprice($itemId)
{
function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0)
return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$data = file_get_contents("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
$pricediv = get_string_between($data, '<div class="current" id="singleFinalPrice"><span class="label">Now:', '</div');
$price = strip_tags($pricediv);
return $price;
}
?>
Take out the get_string_between() out of the getprice() function and you should be good to go:
function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0)
return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
function getprice($itemId)
{
$data = file_get_contents("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
$pricediv = get_string_between($data, '<div class="current" id="singleFinalPrice"><span class="label">Now:', '</div');
$price = strip_tags($pricediv);
return $price;
}