PHP parse facebook json - php

I've search Stack Overflow and Google for an answer but not luck. I'm trying to get the value of each of the locale with php in the following sample (facebook graph api). Any help would be appreciated.
"data": [
{
"id": "123456789/insights/page_fans_locale/lifetime",
"name": "page_fans_locale",
"period": "lifetime",
"values": [
{
"value": {
"en_US": 33975,
"fr_CA": 6906,
"fr_FR": 6105,
"en_GB": 5647
},
"end_time": "2012-03-14T07:00:00+0000"
},
{
"value": {
"en_US": 33992,
"fr_CA": 6906,
"fr_FR": 6107,
"en_GB": 5648
},
"end_time": "2012-03-15T07:00:00+0000"
},
}

First, this fragment is broken. data is a array not a JavaScript object.
Take the correct fragment and analyze data correctly. The best option is:
json_decode();
Here is how to use it.

Related

I want a more consolidate json format

I am getting json array after getting applying query logic.
[
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-20"
},
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "CRP",
"booking_date": "2018-05-20"
},
{
"id": "4",
"diag_name": "Seepz Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-21"
}
]
But i want a more justified json array written below.
[
{
"diag_name": "LT Diagnostics",
"test_name": [
{
"id": "3",
"name" : "Alk PO4"
},
{
"id": "3",
"name" : "CRP"
}
],
"booking_date": "2018-05-20"
},
{
"diag_name": "Seepz Diagnostics",
"test_name": [
{
"id": "4",
"name" : "Alk PO4"
}
],
"booking_date": "2018-05-21"
},
]
I am not getting it,How to do in php. I want a more consolidate json format.
Have you tried changing your SQL query to group by diag_name and booking_date? That would be the first step I’d employ to get the outer data.
Formatting the data in the nested manner you’re after could be a function of whatever record serializer you’re using — does it support nested JSON as a return type, or only flat JSON as your example return value shows?
If the record set -> JSON serializer only ever returns flat data, the comments above are correct that you will have to write your own formatter to change the shape of the JSON yourself...
The accepted answer of this other question may be of help:
Create multi-level JSON with PHP and MySQL
I'm not a PHP guy but this is a typical scenario to use functional programming by means of the monad Map.
Looking online I've found this article that could help you.
Changing datasource output is not always (seldom indeed) a viable option.
Enjoy coding

how to display find() result of mongodb embedded document in php

{
"_id": NumberInt(13),
"name": "vishal",
"friends": [
{
"name1": "vini",
"count": NumberInt(213)
},
{
"name1": "sumesh",
"count": NumberInt(47)
}],
"blog": NumberInt(5)
}
i need to display the name,name1 of all doc & blog in php , using foreach() i got the parent document "name" but dint get name1& blog ?
you can try unwind in aggregation pipeline
db.collection.aggregate([{$unwind:"$friends"}])
Hope it will help

How may i retrieve Mysql data to this JSON format?

I have read about json_encode but still lack the logic in using it for my needs on this particular JSON structure.
Assuming the JSON structure is as follows :
{
"_id": "23441324",
"api_rev": "1.0",
"type": "router",
"hostname": "something",
"lat": -31.805412,
"lon": -64.424677,
"aliases": [
{
"type": "olsr",
"alias": "104.201.0.29"
}
],
"site": "roof town hall",
"community": "Freifunk/Berlin",
"attributes": {
"firmware": {
"name": "meshkit",
"url": "http:k.net/"
}
}
}
Some of the values of the attributes will be taken from the database while some are going to be hardcoded(static) like "type","api_rev". I was thinking of just using concatenation to build the structure but learnt its a bad idea. So if i am to use json_encode how may i be able to handle this structure ? array dimensions etc.

bryntum component integration

I am trying to integrate the bryntum component(schedule) in php. I am not much aware in ext js.
Please see the images here
Here, Name fields are fetching properly, whereas Capacity is not accessing. These values are coming from Zoho CRM.
My code is like Click, whereas r-read.php file is the responsible file for fetching the record from CRM and store it in a json format. It is like
{
"success": true,
"total": 9,
"root": [{
"Id": 1,
"Name": "Sri Test",
"Capicity": "190.0"
}, {
"Id": 2,
"Name": "tester_test01",
"Capicity": "500.0"
}, {
"Id": 3,
"Name": "Tesing room 23",
"Capicity": "5000.0"
}, {
"Id": 4,
"Name": "Test for 6th product",
"Capicity": "5000.0"
}, {
"Id": 5,
"Name": "Banquet hall test-01",
"Capicity": "500.0"
}, {
"Id": 6,
"Name": "test room",
"Capicity": "1000.0"
}, {
"Id": 7,
"Name": "Grande Ballroom",
"Capicity": "4000.0"
}, {
"Id": 8,
"Name": "Cedar Room",
"Capicity": "1400.0"
}, {
"Id": 9,
"Name": "Maple Room",
"Capicity": "1200.0"
}]
}
In the capacity column, it will show like 190.0 , 500.0, 5000.0 etc like Name column.
I'm not familier with the Bryntum schedular component, but most of the time when you have problems like these it's because you didn't define the Capacity field in your model.
I saw you used the following model: Sch.model.Resource. Can it be that is only has the Name field and not Capacity? Your JSON response looks fine to me.
In the sample JSON above, Capacity is spelled Capicity.
See if the same spelling needs can be used everywhere. Maybe then the data will resolve properly.

Can we identify the date on which someone liked my page?

How can we identity the date on which someone liked my page.
is there any way where we can identify the date on which someone liked my page ?
No. You can't even get a list of people that like your page, so you can't get a date they liked it. The only information you can get is how many people like it.
You can view a chart of how many people liked your page over time at Facebook Insights.
Well no, You can make a graph call to the statuses and feeds of a user with valid access_token to get the id and name of the people who liked the post.. The timestamp can be found for the comments though ..
{
"id": "257821xxxxxxx",
"from": {
"name": "Maxxxxxx",
"id": "100xxxxxx"
},
"message": "incredible ..",
"updated_time": "2011-09-15T11:21:15+0000",
"likes": {
"data": [
{
"id": "6xxxxxx6",
"name": "Axxxxxxxxxa"
}
]
},
"comments": {
"data": [
{
"id": "257xxxxxxxxxxxx904",
"from": {
"name": "Maxxxxxxxxxxal",
"id": "1xxxxxxxxxxxxxx"
},
"message": "htxxxxxxxxxxxxxxxxxxxxxxxxxx",
"can_remove": true,
"created_time": "2011-09-15T11:22:06+0000"
}
]
}
}

Categories