Getting random output json - php

I trying to get a youtube channel banner from the youtube api.
But this is very weird.
I use this code:
$json1 = file_get_contents("http://gdata.youtube.com/feeds/api/partners/$channel/branding/default?key=[api-key]&alt=json");
$data1 = json_decode($json1, true);
$banner = $data1['entry']['yt$option'][15]['$t'];
echo $banner;
Now the weird thing, when i refresh te page i get everytime a new value. but sometimes it will stay one value and thats what i need but after some thime the value is changing...
This is the json code:
{
"version":"1.0",
"encoding":"UTF-8",
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$yt":"http://gdata.youtube.com/schemas/2007",
"id":{
"$t":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
},
"published":{
"$t":"2014-02-28T22:08:37.000Z"
},
"updated":{
"$t":"2014-02-28T22:08:37.000Z"
},
"category":[
{
"scheme":"http://schemas.google.com/g/2005#kind",
"term":"http://gdata.youtube.com/schemas/2007#branding"
}
],
"link":[
{
"rel":"self",
"type":"application/atom+xml",
"href":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
},
{
"rel":"edit",
"type":"application/atom+xml",
"href":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
}
],
"yt$option":[
{
"$t":"0",
"name":"channel.banner.image_height.int"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.hd.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.medium.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w854-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.low.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w1280-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.medium.image.url"
},
{
"$t":"#000000",
"name":"channel.global.color"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_banner.jpg?v=52d6ad2b",
"name":"channel.banner.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_low.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.low.image.url"
},
{
"$t":"True",
"name":"channel.modules.show_comments.bool"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w2120-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.hd.image.url"
},
{
"$t":"Welcome to our network Channel. We help Youtubers to earn money and grow with their channel. Being famous on youtube is one of the things you dream about, isn't it? Let us help make your dreams true!\n\nWith us you can choose your own partnership, You also select what you want to earn from your youtube channel! Are you ready to start growing? Partner Now!",
"name":"channel.global.description.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_medium_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.medium_hd.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w1920-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.high.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.medium.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.image.url"
},
{
"$t":"True",
"name":"channel.related_channels.show.bool"
},
{
"$t":"KQvIpdiWrSI",
"name":"channel.unsubscribed_trailer.video_id.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.extra_hd.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_low.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.low.image.url"
},
{
"$t":"True",
"name":"channel.modules.moderate_comments.bool"
},
{
"$t":"Network partner partnership rebase network pewdiepie",
"name":"channel.global.keywords.string"
},
{
"$t":"Rebase Network",
"name":"channel.global.title.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.extra_hd.image.url"
}
]
}
}
This is the one i need(just the url):
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.extra_hd.image.url"
},
Can someone help me please? i really don't understand why it's changing the value every refresh..

You can loop through the results and print out the one where the name matches channel.banner.mobile.extra_hd.image.url
$data1 = json_decode($json1, true);
foreach ($data1['entry']['yt$option'] AS $banner) {
if ($banner['name'] == 'channel.banner.mobile.extra_hd.image.url') {
print $banner['$t'];
}
}

Related

Getting values from meta_data

I have a problem with getting some values from Woocommerce $item object.
I'm trying to extract data from "meta_data" -> "_advanced_woo_discount_item_total_discount" -> initial_price, discounted_price and "discount_value" from "total _discount_details".
I tried with $item->get_meta_data(); but got a blank return.
{
"id":55,
"order_id":11501,
"name":"test",
"product_id":6419,
"variation_id":6421,
"quantity":1,
"tax_class":"",
"subtotal":"182.491803",
"subtotal_tax":"40.15",
"total":"182.491803",
"total_tax":"40.15",
"taxes":{
"total":{"1":"40.148197"},
"subtotal":{"1":"40.148197"}
},
"meta_data":[{
"id":457,
"key":"pa_velikost",
"value":"180cm"
},
{
"id":458,
"key":"_advanced_woo_discount_item_total_discount",
"value":
{
"initial_price":278.3,
"discounted_price":222.64000000000001,
"total_discount_details":
{
"8e39099d383d7d50a8c4fce98e59cc79":
{
"1":
{
"set_discount":0,
"bulk_discount":0,
"simple_discount":
{
"discount_type":"percentage",
"discount_value":"20",
"discount_quantity":1,
"discount_price_per_quantity":55.660000000000004,
"discount_price":55.660000000000004
}
}
}
},
"cart_discount_details":[],
"apply_as_cart_rule":["no"],
"discount_lines":
{
"non_applied":{
"quantity":0,
"discount":0,
"price":278.3,
"calculate_discount_from":278.3
},
"0":
{
"quantity":1,
"discount":55.660000000000004,
"original_price":278.3,
"discounted_price":222.64000000000001
}
},
"cart_quantity":1,
"product_id":6421,
"initial_price_based_on_tax_settings":278.3,
"discounted_price_based_on_tax_settings":222.64000000000001
}
}
]
}
Try with get_meta()
Example:
$item->get_meta('_advanced_woo_discount_item_total_discount')

how to retrieve json data in sequence

i have simple json results like below
{
"code": 200,
"image": "https://example.com/image.jpg",
"result": [
{
"url": "https://example.com/1",
"label": "MP4"
},
{
"url": "https://example.com/2",
"label": "FLV"
},
{
"url": "https://example.com/3",
"label": "MP3"
},
{
"url": "https://example.com/4",
"label": "AVI"
},
{
"url": "https://example.com/5",
"label": "WMV"
}
]
}
as you can see, that there are so many different label paths, and sometimes the sequence of labels is not like the above, it's always changing (random), and I'm trying to get the MP3 label part but can not.
My question is, how to take the sequence of json which has MP3 label?
I have tried with the script below
$uri = json_decode(file_get_contents('https://example.com/json.json'),TRUE);
echo $uri['result'][2]['url'];
but as described above, the position of the MP3 label is always changing, is there a way to overcome it?
Try following code:
$nodesWithMp3Labels = array_map(function($a) {
if (strtolower($a["label"]) == "mp3") {
return $a;
}
}, $uri['result']);
Read more about array_map
With array_map, there will be some blank values if label is not mp3.
Another solution using simple foreach loop:
$nodesWithMp3Labels = [];
foreach ($uri['result'] as $a) {
if (strtolower($a["label"]) == "mp3") {
$nodesWithMp3Labels[] = $a;
}
}
You should use array_filter to get all the results with MP3 label:
$uri = json_decode(file_get_contents('https://example.com/json.json'), true);
$mp3 = array_filter($uri['result'], function($item) {
return $item['label'] === 'MP3';
})

Trying to pre-fill text-tabs in Docusign via Rest API

I am having problems prefilling textTabs for my server templates in my docusign console. My application generates an agreement on our end and is added as a composite template along with another form that is added as a server template with a template id.
The server template has several fields the user needs to be able to fill out. The tabs have been defined and added with the manage template tool in the docusign console.
I have no problems sending the documents and the signHereTab is the only one that is correctly added to the form.
The two problems I have are 1) the fields the user should fill out are never shown on the recieved document, 2) the prefill information I am sending is not received by docusign. Below is the body request I am sending to the docusign REST API:
{
"emailSubject":"Nexogy Service Agreement Signature Request",
"emailBlurb":"Thank you for your interest in our services. Please sign the following agreement to continue with your service installation.",
"status":"sent",
"emailSettings":{
"replyEmailAddressOverride":"sales#nexogy.com",
"replyEmailNameOverride":"Nexogy",
"bccEmailAddresses":[
]
},
"eventNotification":{
"url":"https:\/\/dna.local.com\/documents\/set-status",
"loggingEnabled":true,
"requireAcknowledgment":true,
"useSoapInterface":false,
"includeDocuments":false,
"includeSenderAccountAsCustomField":true,
"envelopeEvents":[
{
"envelopeEventStatusCode":"Sent"
},
{
"envelopeEventStatusCode":"Delivered"
},
{
"envelopeEventStatusCode":"Signed"
},
{
"envelopeEventStatusCode":"Voided"
},
{
"envelopeEventStatusCode":"Declinded",
"includeDocuments":true
},
{
"envelopeEventStatusCode":"Completed",
"includeDocuments":true
}
]
},
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718
}
]
},
"compositeTemplates":[
{
"inlineTemplates":[
{
"sequence":1,
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"signHereTabs":[
{
"xPosition":100,
"yPosition":205,
"documentId":1,
"pageNumber":6,
"fontColor":"BrightBlue"
}
]
}
}
]
},
"documents":[
{
"documentId":1,
"name":"ChuyMPDFAgreement.pdf",
"remoteUrl":"https:\/\/s3.amazonaws.com\/dna_local\/ChuyMPDFAgreement.pdf"
}
]
}
]
},
{
"serverTemplates":[
{
"sequence":2,
"templateId":"ae435358-1410-40fd-803e-273028d19287",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"Full Name",
"value":"Test Tester",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"1"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
},
{
"tabLabel":"Country",
"value":"US",
"pageNumber":"1"
},
{
"tabLabel":"Phone",
"value":"3454657676",
"pageNumber":"1"
},
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":"\\*FullName",
"value":"Test Tester",
"pageNumber":"1"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":3,
"templateId":"017d0d20-754b-4093-8896-ff1c00ee2cda",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"2"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":4,
"templateId":"11a88684-07ac-4ee5-9994-cb88635fb42f",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"2"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
}
]
}
}
]
}
}
]
}
]
}
You can not update template tabs upon creation of the envelope at this time.
Your signHereTabs is in your inlineTemplate, which will add additional tags to your envelope.
If you want to update tabs that are contained in a template via the API, your workflow should look like:
Create Envelope - ("status" : "created")
Modify Envelope - Edit tags here
Send Envelope
All of the documentation around building this workflow is located in DocuSign REST API Guide

display json canvas image from php on page load

I am trying to recreate a signature in a canvas when the page loads.
I have managed to capture a signature and store it in a MySQL database using PHP. It is stored as json data.
Now the problem is this:
I have a page with a canvas element and I can retrieve the json data from the database before the page loads using php but I do not know how to pass this data to the canvas element.
Hoping for a solution because I have spent too many hours messing this up.
Thank you!
json data:
"[
{
\"lx\":87,
\"ly\":6,
\"mx\":87,
\"my\":5
},
{
\"lx\":88,
\"ly\":5,
\"mx\":87,
\"my\":6
},
{
\"lx\":89,
\"ly\":6,
\"mx\":88,
\"my\":5
},
{
\"lx\":89,
\"ly\":7,
\"mx\":89,
\"my\":6
},
{
\"lx\":90,
\"ly\":7,
\"mx\":89,
\"my\":7
},
{
\"lx\":90,
\"ly\":8,
\"mx\":90,
\"my\":7
},
{
\"lx\":90,
\"ly\":10,
\"mx\":90,
\"my\":8
},
{
\"lx\":91,
\"ly\":11,
\"mx\":90,
\"my\":10
},
{
\"lx\":92,
\"ly\":11,
\"mx\":91,
\"my\":11
},
{
\"lx\":92,
\"ly\":12,
\"mx\":92,
\"my\":11
},
{
\"lx\":93,
\"ly\":12,
\"mx\":92,
\"my\":12
},
{
\"lx\":93,
\"ly\":13,
\"mx\":93,
\"my\":12
},
{
\"lx\":95,
\"ly\":15,
\"mx\":93,
\"my\":13
},
{
\"lx\":96,
\"ly\":16,
\"mx\":95,
\"my\":15
},
{
\"lx\":97,
\"ly\":16,
\"mx\":96,
\"my\":16
},
{
\"lx\":97,
\"ly\":17,
\"mx\":97,
\"my\":16
},
{
\"lx\":98,
\"ly\":18,
\"mx\":97,
\"my\":17
},
{
\"lx\":99,
\"ly\":18,
\"mx\":98,
\"my\":18
},
{
\"lx\":99,
\"ly\":19,
\"mx\":99,
\"my\":18
},
{
\"lx\":99,
\"ly\":20,
\"mx\":99,
\"my\":19
},
{
\"lx\":102,
\"ly\":5,
\"mx\":102,
\"my\":4
},
{
\"lx\":101,
\"ly\":5,
\"mx\":102,
\"my\":5
},
{
\"lx\":101,
\"ly\":6,
\"mx\":101,
\"my\":5
},
{
\"lx\":100,
\"ly\":7,
\"mx\":101,
\"my\":6
},
{
\"lx\":100,
\"ly\":8,
\"mx\":100,
\"my\":7
},
{
\"lx\":99,
\"ly\":8,
\"mx\":100,
\"my\":8
},
{
\"lx\":99,
\"ly\":9,
\"mx\":99,
\"my\":8
},
{
\"lx\":98,
\"ly\":9,
\"mx\":99,
\"my\":9
},
{
\"lx\":98,
\"ly\":10,
\"mx\":98,
\"my\":9
},
{
\"lx\":97,
\"ly\":11,
\"mx\":98,
\"my\":10
},
{
\"lx\":96,
\"ly\":12,
\"mx\":97,
\"my\":11
},
{
\"lx\":95,
\"ly\":12,
\"mx\":96,
\"my\":12
},
{
\"lx\":94,
\"ly\":12,
\"mx\":95,
\"my\":12
},
{
\"lx\":93,
\"ly\":12,
\"mx\":94,
\"my\":12
},
{
\"lx\":91,
\"ly\":13,
\"mx\":93,
\"my\":12
},
{
\"lx\":89,
\"ly\":14,
\"mx\":91,
\"my\":13
},
{
\"lx\":89,
\"ly\":15,
\"mx\":89,
\"my\":14
},
{
\"lx\":88,
\"ly\":15,
\"mx\":89,
\"my\":15
},
{
\"lx\":87,
\"ly\":16,
\"mx\":88,
\"my\":15
},
{
\"lx\":86,
\"ly\":17,
\"mx\":87,
\"my\":16
},
{
\"lx\":86,
\"ly\":18,
\"mx\":86,
\"my\":17
},
{
\"lx\":85,
\"ly\":18,
\"mx\":86,
\"my\":18
},
{
\"lx\":85,
\"ly\":19,
\"mx\":85,
\"my\":18
},
{
\"lx\":85,
\"ly\":20,
\"mx\":85,
\"my\":19
},
{
\"lx\":84,
\"ly\":20,
\"mx\":85,
\"my\":20
}
]"
You have 2 options:
Echo into a javascript variable when you generate the page:
echo "<script>var sig = ".$jsonsig.";</script>";
or retrieve it after the page has loaded with an AJAX call
(jQuery in your page script, requires a PHP script to return the JSON code)
$.getJSON("getmysig.php",function(data) {
// create canvas here
});

Pulling data in JSON format from URL

Hi i have been trying to pull data in JSON format. Here is my code
$resourse_url = 'http://www.livepicly.com/app/api.php?method=list_vendor_name';
$json_data = file_get_contents($resourse_url);
$json_output = json_decode($json_data, TRUE);
$vendor = $json_output['vendor_name'][1];
echo "<pre>";
print_r($vendor);
exit(1);
However when i run the code it does not return anything. When i try to access the source URL via firefox, it asks me where to save the JSON data as *.php, however when i access the source URL from Chrome it displays the JSON data as normal.
What do i have to do here? Can anyone point me to a solution? Thx
running the returned json on http://jsonformatter.curiousconcept.com/
{
"result":[
{
"vendor_id":"726",
"vendor_name":"Scusa"
},
{
"vendor_id":"519",
"vendor_name":"Emilie French Restaurant and Bar"
},
{
"vendor_id":"482",
"vendor_name":"Cassis French Fine Dining"
},
{
"vendor_id":"435",
"vendor_name":"Asuka Japanase Dining"
},
{
"vendor_id":"12050",
"vendor_name":"Taipan"
},
{
"vendor_id":"12061",
"vendor_name":"Social House"
},
{
"vendor_id":"12103",
"vendor_name":"Harum Manis Indonesian Restaurant"
},
{
"vendor_id":"12193",
"vendor_name":"Nanny\'s Pavillion (Central Park)"
},
{
"vendor_id":"12272",
"vendor_name":"Bistro Baron"
},
{
"vendor_id":"20704",
"vendor_name":"Kitchenette (Central Park)"
},
{
"vendor_id":"21217",
"vendor_name":"Kitchenette (Plaza Indonesia)"
},
{
"vendor_id":"29859",
"vendor_name":"Momento Restaurant And Bar"
},
{
"vendor_id":"31055",
"vendor_name":"Tortuga Kitchen And Bar"
},
{
"vendor_id":"31056",
"vendor_name":"Tuck And Chug"
},
{
"vendor_id":"31060",
"vendor_name":"AUROZ Gourmet Grill"
}
]
}
it found invalid characters on this line
"vendor_name":"Nanny\'s Pavillion (Central Park)"

Categories