i want to take data of username(david) from this Json , I saw the similar question i try more than 100 times but i can not , I need exact answer if it's possible.
thanks in advance
{
"related_assets": [],
"orders": [],
"auctions": [],
"supports_wyvern": true,
"top_ownerships": [
{
"owner": {
"user": {
"username": "david"
},
"",
"address": "",
"config": ""
},
"quantity": "1"
}
],
"ownership": null,
"highest_buyer_commitment": null
}
and i coded as below :
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//the second parameter turns the objects into an array
$decodedData = json_encode($response, true);
$owner = $decodedData['top_ownerships'][0]['owner'];
$username = $owner['user']['username'];
echo $username;
}
the output is "
please help thanks
your code is completely current! and it works like charm!
but you made a very ambiguous mistake in your JSON code
you're using this ” instead of " (double quotes) there "david” <----
they exactly look the same!
and also you missed {} in the beginning and end of your JSON code
checkout your json code here it's the best tool for this
<?php
$code = '{
"top_ownerships": [{
"owner": {
"user": {
"username": "david"
},
"profile_img_url": "",
"address": "",
"config": ""
},
"quantity": "1"
}]
}';
$decodedData = json_decode($code, true);
$owner = $decodedData['top_ownerships'][0]['owner'];
$username = $owner['user']['username'];
echo $username;
?>
To start with, it's important you understand how to access json fields and key php;
Assuming the above values are stored in a file known as data.json, we can extract the values like this:
$data = file_get_contents('data.json');
//the second parameter turns the objects into an array
$decodedData = json_decode($data, true);
$owner = $decodedData['top_ownerships'][0]['owner'];
$username = $owner['user']['username'];
//echo $username
The above would work if your json file or data is properly encoded.
first you have to store your JSON into a variable, lets call it $json.
$jsonArray = json_decode($json,true);
And set your key name, the key you want from your JSON.
$key = "owner";
$owner= $jsonArray[$key];
You also can read like an object:
$owner= $jsonObj->$key;
Try
$object = json_decode('{"owner": {"user": {"username": "david”},"profile_img_url": "","address": "","config": ""},"quantity": "1"}')
echo $object->owner->user->username
This will make the JSON an object that you can access by using the -> accessor
Related
I've been trying to implement the FedEx rates and transit times API in a PHP script.
I successfully connected with it to get the bearer token.
But when I try to get rates for a simple shipment, it responds with random gibberish.
I don't even get any errors. That's what frustrating.
Here is my code:
ini_set('display_errors', 1);
error_reporting(-1);
$access_url = 'https://apis-sandbox.fedex.com/oauth/token';
$access_headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
$access_fields = "grant_type=client_credentials&client_id=...&client_secret=...";
$resp = curl_me($access_url, $access_headers, $access_fields);
$access_token = json_decode($resp)->access_token;
$rate_url = 'https://apis-sandbox.fedex.com/rate/v1/rates/quotes';
$rate_hdrs = [
'Authorization' => 'Bearer '.$access_token,
'X-locale' => 'en_US',
'Content-Type' => 'application/json'
];
$rate_flds = '{
"accountNumber": {
"value": "..."
},
"requestedShipment": {
"shipper": {
"address": {
"streetLines": [
"..."
],
"city": "...",
"stateOrProvinceCode": "...",
"postalCode": "...",
"countryCode": "US",
"residential": false
}
},
"recipient": {
"address": {
"postalCode": "...",
"countryCode": "US"
}
},
"shipDateStamp": "2022-12-06",
"pickupType": "DROPOFF_AT_FEDEX_LOCATION",
"requestedPackageLineItems": [{
"declaredValue": {
"amount": 123,
"currency": "USD"
},
"weight": {
"units": "LB",
"value": 12
},
"dimensions": {
"length": 12,
"width": 12,
"height": 12,
"units": "IN"
}
}],
"documentShipment": false,
"packagingType": "YOUR_PACKAGING",
"groupShipment": true
},
"carrierCodes": [
"FDXE"
]
}';
$field = build_post_fields($rate_flds);
$resp = curl_me($rate_url, $rate_hdrs, $field);
var_dump($resp);
Here are the two functions I'm using:
function curl_me($url, $headers, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$response = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
return $response;
}
function build_post_fields( $data,$existingKeys='',&$returnArray=[]){
if(($data instanceof CURLFile) or !(is_array($data) or is_object($data))){
$returnArray[$existingKeys]=$data;
return $returnArray;
}
else{
foreach ($data as $key => $item) {
build_post_fields($item,$existingKeys?$existingKeys."[$key]":$key,$returnArray);
}
return $returnArray;
}
}
The second function is from Yisrael Dov's answer to this question.
When I used the first function to get the access token, it worked flawlessly. But I can't figure out why the second time I used it responded with: string(176) "��� �#��W朢%jނ��d�]���(R������I���oFgHY�ת��r҆IH/"�Eq�zi����MJ{��6� �..."
I tried all kinds of different was of encoding and decoding the JSON string. But I get gibberish every time.
I've tried running that gibberish through various decoders, but of course they all returned NULL.
I was expecting at least some kind of error or warning.
Any ideas would be appreciated.
$rate_hdrs = [
'Authorization: Bearer '.$access_token,
'X-locale: en_US',
'Content-Type: application/json',
];
look this: PHP cURL custom headers
Thanks to everyone for the awesome input!
I'm new to CURL, so pardon my not recognizing these mistakes.
I combined Sammitch's comments with Walter KT's answer.
Sammitch was right: the response was gzip encoded. I added curl_setopt($ch, CURLOPT_ENCODING, "gzip"); to my function, and finally got the response (with some handy errors to work through).
I also got rid of the build_post_fields() function.
I am having trouble with the response from Companies House API. I am making the following curl request from a php page:
$request_url_1 ='https://api.companieshouse.gov.uk/company/' ;
$company_number = 11495745;
$request_url_2 = '/officers';
$request_url = $request_url_1 . $company_number . $request_url_2;
$ch = curl_init($request_url);
$headers = array(
'Content-Type: application/json',
'Authorization: Basic '. base64_encode("$chkey:")
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$content = curl_exec($ch);
curl_close( $ch );
$contents = json_decode($content,true);
The following is the response that is 'pasted' on the php page after sending the curl request, and I cannot seem to get at the contents/value of the $contents variable that should contain the curl response.
{
"active_count":1,
"items_per_page":35,
"kind":"officer-list",
"etag":"6cc48213158205c9fa85492a4c2ef0a98b56b2f1",
"resigned_count":2,
"items":[
{
"date_of_birth":{
"year":1963,
"month":2
},
"appointed_on":"2019-08-01",
"nationality":"British",
"address":{
"address_line_1":"Moorside Crescent",
"country":"United Kingdom",
"address_line_2":"Sinfin",
"postal_code":"DE24 9PH",
"locality":"Derby",
"premises":"75"
},
"occupation":"Company Director",
"links":{
"officer":{
"appointments":"/officers/IryiaaBZodlGNaOP0Rf3Pb2GnO8/appointments"
}
},
"name":"MILLER, Eira",
"country_of_residence":"England",
"officer_role":"director"
},
{
"date_of_birth":{
"month":3,
"year":1987
},
"nationality":"English",
"occupation":"Company Director",
"address":{
"locality":"Derby",
"address_line_1":"Moorside Crescent",
"premises":"75",
"country":"United Kingdom",
"postal_code":"DE24 9PH",
"address_line_2":"Sinfin"
},
"appointed_on":"2018-12-10",
"resigned_on":"2019-07-31",
"name":"KING, Kimberley Rachel",
"links":{
"officer":{
"appointments":"/officers/av7G3-iF_9-FXhRH2xm-IxejeGQ/appointments"
}
},
"country_of_residence":"United Kingdom",
"officer_role":"director"
},
{
"address":{
"postal_code":"DE24 9PH",
"locality":"Derby",
"country":"United Kingdom",
"premises":"75",
"address_line_2":"Sinfin",
"address_line_1":"Moorside Crescent"
},
"occupation":"Managing Director",
"nationality":"British",
"appointed_on":"2018-08-01",
"resigned_on":"2018-12-10",
"officer_role":"director",
"country_of_residence":"United Kingdom",
"links":{
"officer":{
"appointments":"/officers/X9nlVD6qIIENMjaH946__4CB3QE/appointments"
}
},
"name":"MARTIN, Katey",
"date_of_birth":{
"month":6,
"year":1968
}
}
],
"links":{
"self":"/company/11495745/officers"
},
"inactive_count":0,
"start_index":0,
"total_results":3
}
I have tried returning result as non-associative array and access it through normal array but no joy there either.
FluffyKitten kindly supplied the following code to perform the extraction of the name field:
$item = $contents["items"];
foreach($item as $items){
echo $items["name"];
}
However, this couldn't access the required data. A print_r of $contents results in '1' and a var_dump (1)
There are a couple of problem with your code:
You are mixing up code for accessing arrays and objects
You are looping when there is no need for loops
You are using json_decode($content,true), and by passing in that true parameter, you are converting the result into associative arrays, but then you try to access items as the property of an object.
Because you have converted the contents to an associative array, you can easily access the information you want using the correct keys, e.g.:
$item = $contents["items"];
foreach($item as $items){
echo "<p>".$items["name"];
}
Reference PHP json_decode Documentation
UPDATE:
Your question has changed totally - it was about how to loop through the variable with the results, but now it seems that the problem is saving the results as a variable in the first place.
You need to set the CURLOPT_RETURNTRANSFER option to true so that the result is not output directly (I assume this is what you mean by the result being "pasted" into the PHP page).
Add this to your CURL code, and if the rest of your code is correct, the result should be saved in the $content variable so you can use it to loop through using the code above:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
I want to use geoplugin. but current Geo plugin show data in json. But how can use this json code in WordPress function
hear example json
{
"geoplugin_request": "122.180.85.165",
"geoplugin_status": 200,
"geoplugin_delay": "2ms",
"geoplugin_credit": "Some of the returned data includes GeoLite data created by MaxMind, available from <a href='http://www.maxmind.com'>http://www.maxmind.com</a>.",
"geoplugin_city": "Ludhiana",
"geoplugin_region": "Punjab",
"geoplugin_regionCode": "PB",
"geoplugin_regionName": "Punjab",
"geoplugin_areaCode": "",
"geoplugin_dmaCode": "",
"geoplugin_countryCode": "IN",
"geoplugin_countryName": "India",
"geoplugin_inEU": 0,
"geoplugin_continentCode": "AS",
"geoplugin_continentName": "Asia",
"geoplugin_latitude": "30.9",
"geoplugin_longitude": "75.85",
"geoplugin_locationAccuracyRadius": "100",
"geoplugin_timezone": "Asia/Kolkata",
"geoplugin_currencyCode": "INR",
"geoplugin_currencySymbol": "₨",
"geoplugin_currencySymbol_UTF8": "₨",
"geoplugin_currencyConverter": 67.9875
}
try this. hope this will help you!!
function getusercountrycode()
{
$ip = $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://www.geoplugin.net/json.gp?
ip=".$ip,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => false
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
$json_a=json_decode($result,true);
$countrycode = $json_a['geoplugin_countryCode'];
return $countrycode;
}
you can use like this
function geo_location(){
$result = file_get_contents('http://www.geoplugin.net/json.gp');
$resultArr = json_decode($result);
echo 'Country ='. $resultArr->geoplugin_countryName;
}
geo_location();
TRY This also
echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));
it will give you an array
we have been working with 3d cart rest response which we have successfully get here is my code.file name example.php which located in my wamp server
<?php
$host = 'https://apirest.3dcart.com';
$version = 1;
$service = 'Orders';
$secureUrl = 'https://xxxxyyyyy.3dcart.net'; // Secure URL is set in Settings->General->StoreSettings
$privateKey = 'xxxxxxxxxxxxxxxx'; // Private key is obtained when registering your app at http://devportal.3dcart.com
$token = 'xxxxxxxxxxxxx'; // The token is generated when a customer authorizes your app
// initialize cURL session
$ch = curl_init($host . '/3dCartWebAPI/v' . $version . '/' . $service);
// set headers
$httpHeader = array(
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json',
'SecureUrl: ' . $secureUrl,
'PrivateKey: ' . $privateKey,
'Token: ' . $token,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
// [ ... addtional cURL options as needed ... ]
$response = curl_exec($ch);
if ($response === false) {
$response = curl_error($ch);
}
curl_close($ch);
we have an access file on a browser using this URL http://localhost/social/example.php get a response in JSON like this without JSON encoded. but I want array this response so we can write CSV file.i have many try to google but no more luck for appropriate solution.thanks in advance.
[{"InvoiceNumberPrefix":"AB-","InvoiceNumber":1000,"OrderID":1,"CustomerID":1,"OrderDate":"2014-01-10T12:44:37","OrderStatusID":1,"LastUpdate":"0001-01-01T00:00:00","UserID":"","SalesPerson":"","ContinueURL":"http://71745179439.3dcart.net/continue_order.asp?orderkey=tl31S22wts7B0hF1","BillingFirstName":"John","BillingLastName":"Doe","BillingCompany":"","BillingAddress":"123 Street","BillingAddress2":"","BillingCity":"Coral Springs","BillingState":"FL","BillingZipCode":"33065","BillingCountry":"US","BillingPhoneNumber":"800-828-6650","BillingEmail":"test#3dcart.com","BillingPaymentMethod":"Online Credit Card","BillingOnLinePayment":true,"BillingPaymentMethodID":"1","ShipmentList":[{"ShipmentID":0,"ShipmentLastUpdate":"0001-01-01T00:00:00","ShipmentBoxes":1,"ShipmentInternalComment":"Sample Order from 3dcart","ShipmentOrderStatus":1,"ShipmentAddress":"123 Street","ShipmentAddress2":"","ShipmentAlias":"","ShipmentCity":"Coral Springs","ShipmentCompany":"","ShipmentCost":0.0,"ShipmentCountry":"US","ShipmentEmail":"","ShipmentFirstName":"Test","ShipmentLastName":"Test","ShipmentMethodID":0,"ShipmentMethodName":"Free Shipping","ShipmentShippedDate":"","ShipmentPhone":"800-828-6650","ShipmentState":"FL","ShipmentZipCode":"33065","ShipmentTax":0.0,"ShipmentWeight":1.0,"ShipmentTrackingCode":"","ShipmentUserID":"","ShipmentNumber":1,"ShipmentAddressTypeID":0}],"OrderItemList":[{"CatalogID":3,"ItemIndexID":1,"ItemID":"1003K","ItemShipmentID":0,"ItemQuantity":1.0,"ItemWarehouseID":0,"ItemDescription":"Tote Bag
Color: Khaki","ItemUnitPrice":1.0,"ItemWeight":3.0,"ItemOptionPrice":0.0,"ItemAdditionalField1":"","ItemAdditionalField2":"","ItemAdditionalField3":"","ItemPageAdded":"Tote-Bag_p_3.html","ItemDateAdded":"2009-06-22T12:05:07","ItemUnitCost":0.0,"ItemUnitStock":5.0,"ItemOptions":",1","ItemCatalogIDOptions":"","ItemSerial":"","ItemImage1":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","ItemImage2":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","ItemImage3":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","ItemImage4":"http://71745179439.3dcart.net/assets/images/default/handbag.jpg","ItemWarehouseLocation":"","ItemWarehouseBin":"","ItemWarehouseAisle":"","ItemWarehouseCustom":""}],"PromotionList":[],"OrderDiscount":0.0,"SalesTax":0.0,"SalesTax2":0.0,"SalesTax3":0.0,"OrderAmount":1.0,"AffiliateCommission":0.0,"TransactionList":[],"CardType":"","CardNumber":"","CardName":"John Doe","CardExpirationMonth":"","CardExpirationYear":"","CardIssueNumber":"","CardStartMonth":"","CardStartYear":"","CardAddress":"","CardVerification":"","RewardPoints":"1","QuestionList":[],"Referer":"http://www.google.com","IP":"","CustomerComments":"Sample Order from 3dcart","InternalComments":"","ExternalComments":""}]
You can use json_decode php function : http://php.net/manual/fr/function.json-decode.php
On your code :
<?php
$host = 'https://apirest.3dcart.com';
$version = 1;
$service = 'Orders';
$secureUrl = 'https://xxxxyyyyy.3dcart.net'; // Secure URL is set in Settings->General->StoreSettings
$privateKey = 'xxxxxxxxxxxxxxxx'; // Private key is obtained when registering your app at http://devportal.3dcart.com
$token = 'xxxxxxxxxxxxx'; // The token is generated when a customer authorizes your app
// initialize cURL session
$ch = curl_init($host . '/3dCartWebAPI/v' . $version . '/' . $service);
// set headers
$httpHeader = array(
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json',
'SecureUrl: ' . $secureUrl,
'PrivateKey: ' . $privateKey,
'Token: ' . $token,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
// [ ... addtional cURL options as needed ... ]
$response = curl_exec($ch);
if ($response === false) {
$response = curl_error($ch);
}
curl_close($ch);
$arrayResponse = json_decode($response, true);
//Do something with your array
Introduction
I don't know what is the structure of the csv file you want to output. You should provide it in your question if you want a better quality answer. Keep in mind though, that you are using 2 different data structures :
JSON is a tree
CSV is a table
So having nested arrays in your json will make this work harder.
Step 1
Check if your json string is valid: json validator
As you will see, the json string response you provided is not.
For the rest of my answer i will consider this part of your response which i made valid :
$string = '
[{
"InvoiceNumberPrefix": "AB-",
"InvoiceNumber": 1000,
"OrderID": 1,
"CustomerID": 1,
"OrderDate": "2014-01-10T12:44:37",
"OrderStatusID": 1,
"LastUpdate": "0001-01-01T00:00:00",
"UserID": "",
"SalesPerson": "",
"ContinueURL": "http://71745179439.3dcart.net/continue_order.asp?orderkey=tl31S22wts7B0hF1",
"BillingFirstName": "John",
"BillingLastName": "Doe",
"BillingCompany": "",
"BillingAddress": "123 Street",
"BillingAddress2": "",
"BillingCity": "Coral Springs",
"BillingState": "FL",
"BillingZipCode": "33065",
"BillingCountry": "US",
"BillingPhoneNumber": "800-828-6650",
"BillingEmail": "test#3dcart.com",
"BillingPaymentMethod": "Online Credit Card",
"BillingOnLinePayment": true,
"BillingPaymentMethodID": "1",
"ShipmentList": [{
"ShipmentID": 0,
"ShipmentLastUpdate": "0001-01-01T00:00:00",
"ShipmentBoxes": 1,
"ShipmentInternalComment": "Sample Order from 3dcart",
"ShipmentOrderStatus": 1,
"ShipmentAddress": "123 Street",
"ShipmentAddress2": "",
"ShipmentAlias": "",
"ShipmentCity": "Coral Springs",
"ShipmentCompany": "",
"ShipmentCost": 0.0,
"ShipmentCountry": "US",
"ShipmentEmail": "",
"ShipmentFirstName": "Test",
"ShipmentLastName": "Test",
"ShipmentMethodID": 0,
"ShipmentMethodName": "Free Shipping",
"ShipmentShippedDate": "",
"ShipmentPhone": "800-828-6650",
"ShipmentState": "FL",
"ShipmentZipCode": "33065",
"ShipmentTax": 0.0,
"ShipmentWeight": 1.0,
"ShipmentTrackingCode": "",
"ShipmentUserID": "",
"ShipmentNumber": 1,
"ShipmentAddressTypeID": 0
}],
"OrderItemList": [{
"CatalogID": 3,
"ItemIndexID": 1,
"ItemID": "1003K",
"ItemShipmentID": 0,
"ItemQuantity": 1.0,
"ItemWarehouseID": 0
}]
}]';
Step 2
Use json_decode() to convert your json to an array this way : The 1st parameter is your json string and the 2nd is a boolean that when set to true will return an associative array. (manual: json_decode)
$array = json_decode($string, true);
Step 3
Create your csv file this way :
$f = fopen('output.csv', 'w');
foreach ($array as $row) {
$result = [];
array_walk_recursive($row, function($item) use (&$result) {
$result[] = $item;
});
fputcsv($f, $result);
}
Of course my answer is based on the json string provided in step 1 !
thanks, all I have to find a solution write curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); then the return value from curl_exec will be the actual result from the successful operation and set false display it only browser
I'm currently working on a website to control my SmartBulbs at home via a webpage. To do so I use the provided API.
I tried my code with an example json response from the manufacturers website. Everything worked fine and all the lights listed in the example response where represented by divs with the names of the lights.
When I tried my code at home (called the API like in the code) I got a valid response but I also got an error which stated Illegal string offset 'label'. What am I doing wrong?
Everything worked fine when I used the example response. The response when I use the API looks the same for me. Shouldn't it also work then?
You can find everything down below. If you need some mor information just ask :)
php code
function get_lights(){
$link = "https://api.lifx.com/v1/lights/all";
$authToken = "I inserted my token here and got a valid response";
$ch = curl_init($link);
$headers = array('Authorization: Bearer ' . $authToken);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $headers);
$response = curl_exec($ch);
$json = json_decode($response, true);
$html = null;
foreach($json as $object)
{
$html.= '<div class="element" onclick="get_info();">' . $object['label'] . '</div>';
}
return $html;
}
example response
[
{
"id": "d3b2f2d97452",
"uuid": "8fa5f072-af97-44ed-ae54-e70fd7bd9d20",
"label": "Left Lamp",
"connected": true,
"power": "on",
"color": {
"hue": 250.0,
"saturation": 0.5,
"kelvin": 3500
},
"infrared": "1.0",
"brightness": 0.5,
"group": {
"id": "1c8de82b81f445e7cfaafae49b259c71",
"name": "Lounge"
},
"location": {
"id": "1d6fe8ef0fde4c6d77b0012dc736662c",
"name": "Home"
},
"last_seen": "2015-03-02T08:53:02.867+00:00",
"seconds_since_seen": 0.002869418,
"product": {
"name": "LIFX+ A19",
"company": "LIFX",
"identifier": "lifx_plus_a19",
"capabilities": {
"has_color": true,
"has_variable_color_temp": true,
"has_ir": true,
"has_multizone": false
}
}
}
]
my API response
[
{
"id":"d073d513bfd6",
"uuid":"02ea5835-9dc2-4323-84f3-3b825419008d",
"label":"MainLight",
"connected":true,
"power":"on",
"color":{
"hue":27.581597619592586,
"saturation":0.0,
"kelvin":2500
},
"zones":null,
"brightness":0.49999237048905165,
"group":{
"id":"d5aa0e1180293e0af56607cbe47f4940",
"name":"MyRoom"
},
"location":{
"id":"451e4b376a38062cdd10c54ab2698975",
"name":"My Home"
},
"product":{
"name":"Color 1000",
"identifier":"lifx_color_a19",
"company":"LIFX",
"capabilities":{
"has_color":true,
"has_variable_color_temp":true,
"has_ir":false,
"has_multizone":false
}
},
"infrared":null,
"last_seen":"2017-02-18T21:40:58.164+00:00",
"seconds_since_seen":0.001675218
}
]
You're setting the wrong option for your cURL handle:
$ch = curl_init($link);
$headers = array('Authorization: Bearer ' . $authToken);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);