cpeel2300 wrote:Being a bit of a web noob, what's the 40-byte 'api key' and how is this generated?
https://prowl.weks.net/publicapi/add?apikey=xxxx&application=test 1&event=test event&description=something happened&priority=1
)<?
$api_key = "xxxx";
$app_name = "App Name";
$event = "An Event";
$description = "I am a description\nnew line1\nline2";
$priority = 0;
$url = "https://prowl.weks.net/publicapi/add?apikey=".$api_key."&application=".$app_name."&event=".$event."&description=".$description."&priority=".$priority;
//replace spaces
$url = str_replace(" ","%20",$url);
//remove £
$url = str_replace("£","",$url);
//replace line breaks with 2 spaces
$url = str_replace("\n","%20%20",$url);
$handle = fopen($url, "rb");
$contents = stream_get_contents($handle);
fclose($handle);
?>
Thickey wrote:Anyone have any ideas?
Thickey wrote:cpeel2300 wrote:Being a bit of a web noob, what's the 40-byte 'api key' and how is this generated?
Chris,
If you log into your prowl account at https://prowl.weks.net/ under settings there is a new API section at the top of the page.
The API interface is much easer for me to get working than the previous way of interaction, I have already changed my PHP script, it only took 5 mins.
jacobb wrote:A snippy roy fielding would argue that's more REST-like than RESTful, but that's getting overly nitty, and a real RESTful API is probably not very useful in this case. Switching to post to be closer to REST couldn't hurt, though
<?php
class Prowl {
private $apikey;
private $application;
function Prowl($apikey, $application) {
$this->apikey = $apikey;
$this->application = $application;
}
function add($priority, $event, $description) {
$url = 'https://prowl.weks.net/publicapi/add?apikey=' . urlencode($this->apikey) .
'&priority=' . urlencode($priority) .
'&application=' . urlencode($this->application) .
'&event=' . urlencode($event) .
'&description=' . urlencode($description);
echo $url; // for debug purposes only
$ch = curl_init($url);
$output = curl_exec($ch);
curl_close($ch);
}
}
$test = new Prowl("%valid_key%", "Some App");
$test->add(0, "Foo", "Bar");
?>
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
Thanks in advice.silverone wrote:
- Code: Select all
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
Warning: fopen(https://prowl.weks.net/publicapi/add?apikey=...&priority=0&application=Some+App&event=Foo&description=Bar) [function.fopen]: failed to open stream: No such file or directory in /home/silver/public_html/prowl.php on line 21silverone wrote:I was using the same approach as you in your prior post.

Thickey wrote:Can I ask from a technical point of view what the advantages of using cURL are over using fopen (see my code above for an example). the fopen negotiates the https with out any problems at all. Am I missing something?
$url = /* some valid prowl url */
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
<?php
class Prowl {
private $apikey;
private $application;
function Prowl($apikey, $application) {
$this->apikey = $apikey;
$this->application = $application;
$this->verify();
}
function add($priority, $event, $description) {
$options = array(
'apikey' => $this->apikey,
'priority' => $priority,
'application' => urlencode($this->application),
'event' => urlencode($event),
'description' => urlencode($description)
);
$this->request('https://prowl.weks.net/publicapi/add', $options);
}
function verify() {
$options = array('apikey' => $this->apikey);
$this->request('https://prowl.weks.net/publicapi/verify', $options);
}
private function request($file, $options) {
$url = $file;
$first = true;
foreach ($options as $key => $value) {
$url .= ($first ? '?' : '&') . $key . '=' . $value;
$first = false;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);
}
}
// Sample code
$test = new Prowl("0123456789abcdef0123456789abcdef01234567", "Some Application");
$test->add(0, "Event", "Description");
?>Users browsing this forum: No registered users