I have an Ers 1000 with cloud plan from Sony and i am trying to setup ENDPOINT on the sony site in order to use some features. I am using a PHP server than run fine, but no way to get the endpoint validation on site website. I used a php page to get the "challenge" value, and i send it back to body using php "echo", this works fine with postman but no way on sony site. I noticed the way they post the challenge is harder that common post so i used
$source1 = json_decode(file_get_contents("php://input"));
And I finished with a page showing the body like a json :
$post = json_decode(file_get_contents('php://input'), true);
echo($post);
this give {"challenge":"1324111"}
on sony I enter this url : https://xxxserver.com/aibo/ where index.php have the code
any idea on how to implement this API endpoint? as sony error don't give details on what is wrong. thanks!
here are few points allowing me to do it :
header('Content-type: text/plain; charset=utf-8');
in an if loop :
http_response_code(200);
this line is important to read the data sent to body by sony :
$source1 = array();
$source1 = json_decode(file_get_contents("php://input"),true);
not gone deep with this one but it's the idea for the security key
$headers = apache_request_headers();
$token = $headers['X-Security-Token'];
about data sent back as json i use smary but the result will be like a blank page with only :
{ "challenge":"thesourcechallengekey"}
got from :
$source1['challenge'];
Note : i also noticed that .htaccess file could add too many restrictions, it was not origin of my issue but if i enable extra settings and controls to my php.ini it often block the Endpoint check, so try first removing all settings that are not mandatory in order to test the Endpoint.
About sending back the actions to aibo curl in PHP works fine, here is a small basic sample :
$post_url = 'https://public.api.aibo.com/v1/devices';
$data = '{}' ;
$postData = array();
header('Content-Type: application/json'); // Specify the type of data
// Setup cURL
$ch = curl_init($post_url);
curl_setopt_array($ch, array(
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: '.$bearer)
));
Where $bearer = "Bearer yourbearercodehere";
And you have to edit the first URL to add sony API endpoint action link
Related
I want to achieve this workflow from my server, using PHP and a service account. Basically, I just want to generate a resume URI on my server, send it on my client and do the upload from my client. But the PHP SDK doesn't provide a method to do this !
I do not want to use Signed URL, as they do not allow me to control the file being uploaded. I just want to make a simple POST, like described in the page I linked, using the credentials (the Bearer token) loaded by the PHP SDK.
Is there anyway to do this without re-coding the entire auth part ?
Do you want to reproduce the steps provided in [1] to save the resumable session URI using PHP?
If this is the case, I can think on that you may build a simple PHP POST request using the file_get_contents() function (use http_build_query() function [2] to generate a URL-encoded query string to specify POST variables).
For example, for a resumable session (as shown in the documentaion [1]):
POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000
{
"name": "myObject"
}
You may try a PHP script for making this POST request. A possible option for a PHP script would be similar to this:
<?php
$post = http_build_query(array('name'=>'myObject')); // POST variable "name"
// Create the HTTP Headers
$headers = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/json\r\n"."charset=UTF-8\r\n"."X-Upload-Content-Type: image/jpeg\r\n"."X-Upload-Content-Length: 2000000\r\n",
'content' => $post
)
);
$s_context = stream_context_create($headers);
$uri = file_get_contents('https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable', false, $s_context);
?>
Could you try this PHP script and post your results?
[1] https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload
[2] http://php.net/manual/en/function.http-build-query.php
Everything I look at online is showing how to use OAuth & Curl to make a POST request, but I want to make a get request to the Mailchimp API and I'm not getting any response it seems. I've already managed to go through the authentication and get the user's token & api URL. Now I'm just trying to pull in their lists. Here's the CURL code I've got currently:
$headers = array(
"Content-type: application/json",
"Authorization: OAuth ".$user['mct']
);
$curl = curl_init();
curl_setopt_array($curl,array(
CURLOPT_URL => "https://".$user['dc'].".api.mailchimp.com/3.0/lists",
CURLOPT_USERAGENT => "oauth2-draft-v10",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_ENCODING => ''
));
$tresp = curl_exec($curl);
$lists = json_decode($tresp,true);
curl_close($curl);
Assuming $user['mct'] and $user['dc'] contain the proper values, any idea what I'm doing wrong here?
In case anyone ends up googling and finding this, my problem was that the user information I was getting from wordpress' get_results() function was an object and not an array. Took me forever to realize because for some reason this part of my plugin is preventing me from using print_r().
Now that it's actually going to the Mailchimp API I'm able to get and debug whatever error they're sending back.
have a look at below snippet inside my PHP code :
function SMS(){
$msg1="".$bookingNo."\n".$guestName."\n".$guestEmail."\n".$guestPhone."\n".$guestAddress."\n".$place."\n".$account."\n".$reportingDate."\n".$reportingTime."";
file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}
The problem is this that this http link is sending SMS successfully when run on browser window,
with some dummy text in &message=.
But when I am assigning all defined and tested variables inside $msg1 & calling it in same url.
Woosh, it shows NO ERROR & nothing happens, on calling this function. NO SMS.
I wonder where m wrong ?
Thanks
UPDATED CODE :
function SMS(){
$bookingNo=$_REQUEST['bookingNo'];
$guestName=$_REQUEST['guestName'];
$guestEmail=$_REQUEST['guestEmail'];
$guestPhone=$_REQUEST['guestPhone'];
$guestAddress=$_REQUEST['guestAddress'];
$place=$_REQUEST['place'];
$account=$_REQUEST['account'];
$reportingDate=$_REQUEST['reportingDate'];
$reportingTime=$_REQUEST['reportingTime'];
$msg1="".$bookingNo."\n".$guestName."\n".$guestEmail."\n".$guestPhone."\n".$guestAddress."\n".$place."\n".$account."\n".$reportingDate."\n".$reportingTime."";
file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}
}
SMStoDriver();
Newline characters are not allowed in URLs. You need to encode the message:
function SMS(){
$bookingNo=$_REQUEST['bookingNo'];
$guestName=$_REQUEST['guestName'];
$guestEmail=$_REQUEST['guestEmail'];
$guestPhone=$_REQUEST['guestPhone'];
$guestAddress=$_REQUEST['guestAddress'];
$place=$_REQUEST['place'];
$account=$_REQUEST['account'];
$reportingDate=$_REQUEST['reportingDate'];
$reportingTime=$_REQUEST['reportingTime'];
$msg1=urlencode("Booking No: $bookingNo\nName: $guestName\n Email: $guestEmail\nPhone: $guestPhone\nAddress: $guestAddress\nPlace: $place\nAccount: $account\nDate: $reportingDate\nTime: $reportingTime");
file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}
}
It looks like you are trying to use the file method to make the web request. Perhaps your PHP ini is configured to not allow file I/O requests to URLs.
You would be better off making the web request with something like cURL.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message=test',
));
$resp = curl_exec($curl);
curl_close($curl);
I have a webcam via Android IP Camera App. I'm writing a php script perform an OCR on a temperature sensor to read the digits and warn me when it goes past a specific temperature. The URL I wish to grab is a shot.jpg via the cam's IP, however the webcam has a username and password of authorization: basic. I was able to get through the authentication with the first method, but it simply outputs a shit ton of random characters. The second method loads a picture, but the src is incorrect. Any suggestions on how to properly format the first method with the content-type would be amazing. Thanks
//METHOD 1
$context = stream_context_create(array(
'http' => array('header' => "Authorization: Basic " . base64_encode("$username:$password"))
));
$data = file_get_contents($url, false, $context);
echo $data;
//METHOD NUMBER 2
header('Authorization: Basic' . base64_encode("$username:$password"));
header('Content-Type: image/jpg');
$data = file_get_contents($url, false);
echo $data;
You're not outputting the correct Content-Type: in example 1. file_get_contents does not pass it on. So the image will be sent to the browser under the assumption it were a HTML page.
This way:
$data = file_get_contents($url, false, $context);
header('Content-Type: image/jpg');
echo $data;
Also, try curl (which also supports HTTP), for simplifying the login credential use.
In your second example you are using a page response header(). The Authorization: line will not be passed over the file_get_contents() URL request there.
I have a basic API endpoint set up on my site, which a 3rd party site will use to verify certain info that is entered into a form by the user.
Here's the flow:
1. User is on 3rd party site.
2. User enters info into a form
3. Info is sent to my site's endpoint.
4. My site checks the information and returns a JSON object.
As you can see from #4, my API is currently set up to return a JSON object. After the info is checked, something like this happens:
header('content-type: application/json; charset=utf-8');
echo json_encode($response);
exit;
However, the 3rd party site is only set up to receive URL variables. Is there a way to pass back url variables programmatically? I realize I could theoretically send a new request, but it's not clear to me where that request should go (the internal workings of the 3rd party site aren't well documented), so I'd much prefer to send it as a response.
I hope this makes sense. Please comment if it doesn't. Thanks in advance!
You don't get to send GET/POST parameters in the response, but in the response body you can send whatever you want in whatever format you want - and they can use curl or file_get_content and parse it on their side (3rd party's website).
For example (on the 3rd party's website):
//setting a call to your server
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: text/xml\r\n".
"Authorization: Basic ".base64_encode("$https_user:$https_password")."\r\n",
'content' => $body,
'timeout' => 60
)
);
$context = stream_context_create($opts);
$url = 'https://'.$https_server;
// Here they call your server
$result = file_get_contents($url, false, $context, -1, 40000);
// Here you'll parse the $result